/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFrameBase.java
 * @author Aitor Eguzkiza
 * Created on 17-may-2010, 13:52:08
 */

package GUI;

/**
 *
 * @author aeguzkiza
 */
import DBConnections.MySQL_Query;
import model.Consultation;
import model.DB2Hash;
import model.Patient;
//import view.PatientTreeView;
//import view.WorklistTreeView;
import dcm4che.dcmSND;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UnsupportedLookAndFeelException;
import libraries.MultimediaLibrary;
import libraries.LanguageLibrary;

import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.Hashtable;
import javax.swing.ImageIcon;
//import libreria.FunctionLibrary;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import DBConnections.ServerData;
import java.sql.ResultSet;


import java.util.Arrays;

// GUI Libraries.
import com.nilo.plaf.nimrod.NimRODLookAndFeel;
import controller.Controller;
import java.awt.Rectangle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/*import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
import com.sun.java.swing.plaf.motif.MotifButtonUI;
import com.sun.java.swing.plaf.motif.MotifLookAndFeel;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

import com.digitprop.tonic.*;
import com.seaglasslookandfeel.SeaGlassLookAndFeel;*/
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import libraries.Application;
import libraries.PathLibrary;
import view.PatientTreeView;
import view.WorklistTreeView;
import libraries.FileLibrary;
import libraries.JTextFieldFilter;
import view.DicomAttribute;
import view.Server;

public final class JFrameBase extends javax.swing.JFrame {
    Date today = new Date();
    public DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    
    // Screen and image sizes definition.
    //public Dimension screenSize;
    //private static double scaleFactor;
    
    // Hashtables definition:
    //private List<String> patientIdentify = new ArrayList<String>();
    private Hashtable patientList = new Hashtable();
    private Hashtable studyHash = new Hashtable();
    private Hashtable physicianHash = new Hashtable();
    //private Hashtable testHash = new Hashtable();
    
    public ArrayList<DicomAttribute> columnNames = new ArrayList<DicomAttribute>();
    
    // Strings globales.
    public String infoTxt = "Información";
    public String errorTxt = "Error!";
    public String MYSQL_EXCEPTION = "Excepción MySQL";
    public String EXCEPTION = "Excepción"; 
    private static String addPatientQuestion = "¿Esta seguro/a de querer guardar los cambios sobre el paciente seleccionado?";
    private static String addStudyQuestion = "¿Esta seguro/a de querer guardar los cambios sobre el estudio seleccionado?";
    private static String addAcquisitionQuestion = "¿Esta seguro/a de querer guardar los cambios sobre la adquisición seleccionada?";
    private static String patientTreeTitle = "Lista de pacientes";
    private static String worklistTreeTitle = "Lista de trabajo";
    private static String initConfig = "Configuración inicial";
    public static String newPatient = " Nuevo paciente";
    public static String newStudy = " Nuevo estudio";
    public static String newAcquisition = " Nueva adquisición";

    public String emptyChar = "El primer carácter de los siguientes campos debe estar vacío:";
    public String emptyField = "Falta por definir algún campo obligatorio del formulario. Compruebe los siguientes:";
    public String emptyImageLabel = "No se ha cargado ninguna imagen. \nCompruebe que la extensión del archivo sea de tipo imagen.";
    public static Integer randomMargin = 10000;

    public Integer selectedPatientId;
    public Integer selectedStudyId;
    public Integer selectedAcquisitionId;

    private JTextFieldFilter jtff;

    public view.Patient x = null;
    public view.Study y = null;
    public view.Acquisition z = null;

    public DefaultMutableTreeNode topPatient = new DefaultMutableTreeNode(patientTreeTitle);
    public static DefaultMutableTreeNode topWorklist = new DefaultMutableTreeNode(worklistTreeTitle);
    
    // DEFINICIÓN DE LAS VARIABLES QUE SE VAN A NECESITAR MÁS ADELANTE:
    //JFrameConfig FC = new JFrameConfig(); // Not used.
    Consultation C = new Consultation();
    Patient P = new Patient();
    public MySQL_Query DB = new MySQL_Query();     // Functions related with MySQL connections.
    public PathLibrary PL = new PathLibrary();     // Contains paths to each folder of interest in the soft.
    MultimediaLibrary MLib = MultimediaLibrary.getInstance();
    LanguageLibrary LLib = new LanguageLibrary();
    FileLibrary FLib = new FileLibrary();
    ServerData SD;
    Application AP = new Application();
        
    // DEFINICIÓN DE LOS IMAGEICON
    ImageIcon logo = MLib.getImageIcon(1);
    ImageIcon iconV = MLib.getImageIcon(3);
    ImageIcon error = MLib.getImageIcon(6);
    ImageIcon tick = MLib.getImageIcon(7);
    ImageIcon fondo = MLib.getImageIcon(8);

    Object[] NoImage = LLib.getImageError(0);
    private ImageIcon loaded;   // Define la variable que contendrá la imagen capturada para Dicomizar.
    public JFileChooser ImageFileChooser = new javax.swing.JFileChooser();
    Date fechaActual = new Date();

    // SQL Query resulset.
    private ResultSet rs;   // Patient Name.
    private ResultSet rs2;  // Study Id & Physicians name.

    // CONSTRUCCTION OF JTREE:
    //JTree Patient and Worklist TreeModels;
    public DefaultTreeModel model;
    public DefaultTreeModel modelPatient;

    // Worklist public variables
    Vector Physician_Id = new Vector();
    Vector PerformingPhysiciansName = new Vector();
    Vector PerformingPhysiciansSurName = new Vector();
    Vector PhysicianId = new Vector();
    private Calendar calendar;

    // Predefined paths:
    public String savePath = PL.getimgs2savePath();
    private String inPath = PL.getimgs2sendPath();
    
    // Send table model
    public DefaultTableModel tableModel;               // Table model for acquisitions to send.
    private Application application;
    private Controller controller;
    private Consultation consultation;
    private PatientTreeView patientTreeView;
    private WorklistTreeView worklistTreeView;

    // Field lenght definitions.
    // Patient
    private int HCEInputLenght = 7; // 64 in DICOM.
    private int NameInputLenght = 64;
    private int SurnameInputLenght = 64;
    private int PatientCommentsTextAreaLenght = 10240;

    // Study
    private int RxRightEyeInput1Lenght = 4;
    private int RxRightEyeInput2Lenght = 4;
    private int RxRightEyeInput3Lenght = 3;
    private int RxLeftEyeInput1Lenght = 4;
    private int RxLeftEyeInput2Lenght = 4;
    private int RxLeftEyeInput3Lenght = 3;
    private int StudyCommentsTextAreaLenght = 10240;

    // Aqcuisition
    private int ImagePathInputLenght = 150;
    private int FixationLossesInputLenght = 3;
    private int SensibilityInputLenght = 5;
    private int FalsePositivesInputLenght = 3;
    private int FalseNegativesInputLenght = 3;
    private int TestDurationInput1Lenght = 2;
    private int TestDurationInput2Lenght = 2;
    private int DMInput1Lenght = 5;
    private int DMInput2Lenght = 6;
    private int DSMInput1Lenght = 5;
    private int DSMInput2Lenght = 6;
    private int SFInput1Lenght = 5;
    private int CPSDInput1Lenght = 5;

    // Field maxValue definitions.
    private int percentageMaxValue = 100;
    private int RxSphericalMaxValue = 25;
    private int RxCilinderMaxValue = 10;
    private int cylinderAxisMaxValue = 180;
    private int minuteMaxValue = 60;
    private int decibelMaxValue = 100;

    // Max decimals definitions.
    private int PmaxDecimals = 3;

    // Default values for Study.
    public String defaultFixationStrategy = "Mirada/Punto ciego";
    public String defaultStimulusSize = "III";
    public String defaultStimulusColor = "Blanco";
    public String defaultBackgruondLuminance = "31.5";
    public String defaultBackgruondColor = "Blanco";

    // Default values for Acquisition.
    public String defaultGlobalIndexName = "Prueba de hemicampo en glaucoma (PHG)";
    public String defaultPHG = "Dentro de los límites normales";
    public boolean defaultFoveal = false;  // Foveal thresold disabled.
    public boolean defaultDSM = false;
    public boolean defaultDM = false;
    public boolean defaultSF = false;
    public boolean defaultCPSD = false;

    // Date picker.
    //private JXDatePicker datePicker; 
    

    /** Creates new form JFrameBase */
    public JFrameBase() {
        try {               
            UIManager.setLookAndFeel(new NimRODLookAndFeel());
            //UIManager.setLookAndFeel(new NimbusLookAndFeel());
            //UIManager.setLookAndFeel(new WindowsLookAndFeel());
            //UIManager.setLookAndFeel(new MotifLookAndFeel());
            //UIManager.setLookAndFeel(new TonicLookAndFeel());
            //UIManager.setLookAndFeel(new SeaGlassLookAndFeel());

        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
        }        
        //initTree();
        //initComponents();        
        //updateWorklistTree();
        
    }
        

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        SexButtonGroup = new javax.swing.ButtonGroup();
        EyeButtonGroup = new javax.swing.ButtonGroup();
        FovealButtonGroup = new javax.swing.ButtonGroup();
        WorklistDateButtonGroup = new javax.swing.ButtonGroup();
        HCERegisterDialog = new javax.swing.JDialog();
        UserLabel = new javax.swing.JLabel();
        UserInput = new javax.swing.JTextField();
        PasswordLabel = new javax.swing.JLabel();
        PasswordInput = new javax.swing.JPasswordField();
        GoButton = new javax.swing.JButton();
        ProgressScrollPane = new javax.swing.JScrollPane();
        ProgressTextPane = new javax.swing.JTextPane();
        imageDialog = new javax.swing.JDialog();
        ImageLabel = new javax.swing.JLabel();
        Worklist = new javax.swing.JFrame();
        WorklistDate_WF = new javax.swing.JLabel();
        selectedServerComboBox1 = new javax.swing.JComboBox();
        RefreshButton_WF = new javax.swing.JButton();
        WorklistLayeredPane = new javax.swing.JLayeredPane();
        PatientIdLabel_WF = new javax.swing.JLabel();
        PatientIdInput_WF = new javax.swing.JTextField();
        PatientNameLabel_WF = new javax.swing.JLabel();
        PatientNameInput_WF = new javax.swing.JTextField();
        AccessNumberLabel_WF = new javax.swing.JLabel();
        AccessNumberInput_WF = new javax.swing.JTextField();
        StudyDescriptionLabel_WF = new javax.swing.JLabel();
        StudyDescriptionInput_WF = new javax.swing.JTextField();
        WorklistDateLabel_WF = new javax.swing.JLabel();
        WorklistDate_Radio1 = new javax.swing.JRadioButton();
        WorklistDate_Radio2 = new javax.swing.JRadioButton();
        WorklistDate_Radio3 = new javax.swing.JRadioButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        WorklistXTable = new org.jdesktop.swingx.JXTable();
        jProgressBar1 = new javax.swing.JProgressBar();
        ReferralNote = new javax.swing.JFrame();
        ReferralDataLayeredPane = new javax.swing.JLayeredPane();
        PatientLabel = new javax.swing.JLabel();
        PatientIdLabel = new javax.swing.JLabel();
        PatientIdTextField = new javax.swing.JTextField();
        PatientNameLabel = new javax.swing.JLabel();
        PatientNameTextField = new javax.swing.JTextField();
        PatientSurNameLabel = new javax.swing.JLabel();
        PatientSurNameTextField = new javax.swing.JTextField();
        PatientBirthDateLabel = new javax.swing.JLabel();
        PatientBirthDateTextField = new javax.swing.JTextField();
        Procedure = new javax.swing.JLabel();
        RequestingPhysicianLabel = new javax.swing.JLabel();
        RequestingPhysicianTextField = new javax.swing.JTextField();
        RequestedProcedureDescriptionLabel = new javax.swing.JLabel();
        RequestedProcedureDescriptionTextField = new javax.swing.JTextField();
        ScheduledProcedureStepDescriptionLabel = new javax.swing.JLabel();
        ScheduledProcedureStepDescriptionTextField = new javax.swing.JTextField();
        TestPatternLabel = new javax.swing.JLabel();
        TestPatternTextField = new javax.swing.JTextField();
        TestStrategyLabel = new javax.swing.JLabel();
        TestStrategyTextField = new javax.swing.JTextField();
        TestModeLabel = new javax.swing.JLabel();
        TestModeTextField = new javax.swing.JTextField();
        ScheduledProcedureStartDateLabel = new javax.swing.JLabel();
        ScheduledProcedureStartDateTextField = new javax.swing.JTextField();
        ScheduledProcedureStartTimeLabel = new javax.swing.JLabel();
        ScheduledProcedureStartTimeTextField = new javax.swing.JTextField();
        PhysicianLabel = new javax.swing.JLabel();
        PerformingPhysicianNameComboBox1 = new javax.swing.JComboBox();
        PatientSexLabel = new javax.swing.JLabel();
        PatientSexField = new javax.swing.JTextField();
        newReferralNoteButton = new javax.swing.JButton();
        newReferralNoteButton1 = new javax.swing.JButton();
        EyeDilatationLayeredPane1 = new javax.swing.JLayeredPane();
        DilatationRadioButton1 = new javax.swing.JRadioButton();
        DilatationRadioButton3 = new javax.swing.JRadioButton();
        ErrorDialog = new javax.swing.JDialog();
        jScrollPane6 = new javax.swing.JScrollPane();
        ErrorPane = new javax.swing.JTextPane();
        Send = new javax.swing.JFrame();
        jScrollPane7 = new javax.swing.JScrollPane();
        dcmsndTable = new javax.swing.JTable(){
            @Override
            public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                int sent = 0;
                //System.out.println("rowIndex: "+rowIndex+" columnIndex: "+columnIndex);
                String isSent= dcmsndTable.getValueAt(rowIndex, dcmsndTable.getColumnModel().getColumnIndex("Enviado")).toString();  // The current acquisition is already sent.
                /*if(isSent.equals("No") && toggle == true && extend == false){
                    return; // Don't select (Do nothing).
                }else */if(isSent.equals("Sí") && (toggle == false || extend == true)){
                    return; // Don't select (Do nothing).
                }else{ // Select it.
                    super.changeSelection(rowIndex, columnIndex, toggle, extend);
                }
            }

        };
        dcmSndButton = new javax.swing.JButton();
        dcmDeleteButton = new javax.swing.JButton();
        SelectAllButton = new javax.swing.JToggleButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        dcmSndBuffer = new javax.swing.JTextArea();
        SendingProgressBar = new javax.swing.JProgressBar();
        SendingLabel = new javax.swing.JLabel();
        SelectedServerLabel = new javax.swing.JLabel();
        selectedServerComboBox = new javax.swing.JComboBox();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        PatientListLabel = new javax.swing.JLabel();
        PatientListRefreshButton = new javax.swing.JButton();
        PatientSearchInput = new javax.swing.JTextField();
        RemovePatientButton = new javax.swing.JButton();
        SendButton = new javax.swing.JButton();
        ProgressBar = new javax.swing.JProgressBar();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        DemographicPanel = new javax.swing.JPanel();
        HCE_checkLabel = new javax.swing.JLabel();
        patientLayeredPane = new javax.swing.JLayeredPane();
        SexLabel = new javax.swing.JLabel();
        PatientCommentsLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        PatientCommentsTextArea = new javax.swing.JTextArea();
        PatientSaveButton = new javax.swing.JButton();
        ButtonsLayeredPane = new javax.swing.JLayeredPane();
        SexM_Radio = new javax.swing.JRadioButton();
        SexF_Radio = new javax.swing.JRadioButton();
        BirthDateInput = new org.jdesktop.swingx.JXDatePicker();
        BirthDateLabel = new javax.swing.JLabel();
        SurnameLabel = new javax.swing.JLabel();
        SurnameInput = new javax.swing.JTextField();
        NameInput = new javax.swing.JTextField();
        NameLabel = new javax.swing.JLabel();
        HCELabel = new javax.swing.JLabel();
        HCEInput = new javax.swing.JFormattedTextField();
        ClinicPanel = new javax.swing.JPanel();
        StudyNameLabel = new javax.swing.JLabel();
        StudyNameInput = new javax.swing.JTextField();
        StudyDateLabel = new javax.swing.JLabel();
        StudyDateInput = new org.jdesktop.swingx.JXDatePicker();
        ClinicDataLayeredPane = new javax.swing.JLayeredPane();
        RxLabel1 = new javax.swing.JLabel();
        RxPane1 = new javax.swing.JLayeredPane();
        RxRightEyeLabel = new javax.swing.JLabel();
        RxLeftEyeLabel = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        RxRightEyeInput1 = new javax.swing.JTextField();
        RxRightEyeLabel1 = new javax.swing.JLabel();
        RxRightEyeInput2 = new javax.swing.JTextField();
        RxRightEyeLabel2 = new javax.swing.JLabel();
        RxRightEyeInput3 = new javax.swing.JTextField();
        RxLeftEyeInput1 = new javax.swing.JTextField();
        RxLeftEyeLabel1 = new javax.swing.JLabel();
        RxLeftEyeInput2 = new javax.swing.JTextField();
        RxLeftEyeLabel2 = new javax.swing.JLabel();
        RxLeftEyeInput3 = new javax.swing.JTextField();
        RxLeftEyeLabel3 = new javax.swing.JLabel();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        TestPatternsLabel = new javax.swing.JLabel();
        TestPatternsComboBox = new javax.swing.JComboBox(LLib.getTestType());
        TestModesLabel = new javax.swing.JLabel();
        TestModesComboBox = new javax.swing.JComboBox(LLib.getTestMode());
        studyCommentsLabel = new javax.swing.JLabel();
        TestStrategyComboBox = new javax.swing.JComboBox(LLib.getStrategy());
        PerformingPhysicianLabel = new javax.swing.JLabel();
        PerformingPhysicianNameComboBox = new javax.swing.JComboBox();
        jScrollPane9 = new javax.swing.JScrollPane();
        StudyCommentsTextArea = new javax.swing.JTextArea();
        TestStrategyLabel1 = new javax.swing.JLabel();
        StudyDescriptionLabel = new javax.swing.JLabel();
        jScrollPane10 = new javax.swing.JScrollPane();
        StudyDescriptionTextArea = new javax.swing.JTextArea();
        StudySaveButton = new javax.swing.JButton();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        FixationStrategyLabel = new javax.swing.JLabel();
        FixationStrategyComboBox = new javax.swing.JComboBox(LLib.getFixationMonitor());
        FixationTargetLabel = new javax.swing.JLabel();
        FixationTargetComboBox = new javax.swing.JComboBox(/*LLib.getFixationTarget()*/);
        StimulusLabel = new javax.swing.JLabel();
        StimulusLayeredPane = new javax.swing.JLayeredPane();
        StimulusLabel2 = new javax.swing.JLabel();
        StimulusComboBox1 = new javax.swing.JComboBox(LLib.getStimulusSize());
        StimulusLabel3 = new javax.swing.JLabel();
        StimulusComboBox2 = new javax.swing.JComboBox(LLib.getStimulusColor());
        BackgroundLuminanceLabel1 = new javax.swing.JLabel();
        BackgroundLuminanceLayeredPane = new javax.swing.JLayeredPane();
        BackgroundLuminanceLabel2 = new javax.swing.JLabel();
        BackgroundLuminanceLabel3 = new javax.swing.JLabel();
        BackgroundLuminanceComboBox2 = new javax.swing.JComboBox(LLib.getBackgroundColor());
        BackgroundLuminanceComboBox1 = new javax.swing.JComboBox(LLib.getBackgroundLuminance());
        ImagePanel = new javax.swing.JPanel();
        ReliabilityLayeredPane = new javax.swing.JLayeredPane();
        FixationLossesLabel = new javax.swing.JLabel();
        FixationLossesInput = new javax.swing.JTextField();
        FixationLossesCheckedInput = new javax.swing.JTextField();
        FalsePositivesLabel1 = new javax.swing.JLabel();
        FalsePositivesInput = new javax.swing.JTextField();
        FalsePositivesLabel2 = new javax.swing.JLabel();
        FalseNegativesLabel1 = new javax.swing.JLabel();
        FalseNegativesInput = new javax.swing.JTextField();
        FalseNegativesLabel2 = new javax.swing.JLabel();
        FovealLabel = new javax.swing.JLabel();
        FovealLayeredPane = new javax.swing.JLayeredPane();
        FovealRadioButton1 = new javax.swing.JRadioButton();
        FovealRadioButton2 = new javax.swing.JRadioButton();
        SensibilityLabel1 = new javax.swing.JLabel();
        SensibilityInput = new javax.swing.JTextField();
        SensibilityLabel2 = new javax.swing.JLabel();
        TestDurationLabel1 = new javax.swing.JLabel();
        TestDurationInput1 = new javax.swing.JTextField();
        TestDurationLabel2 = new javax.swing.JLabel();
        TestDurationInput2 = new javax.swing.JTextField();
        TestDurationLabel3 = new javax.swing.JLabel();
        FixationLossesLabel1 = new javax.swing.JLabel();
        GlobalIndicesPane = new javax.swing.JLayeredPane();
        GlobalIndexNameLabel = new javax.swing.JLabel();
        PHGComboBox = new javax.swing.JComboBox(LLib.getPHG());
        DMLabel1 = new javax.swing.JLabel();
        DMInput1 = new javax.swing.JTextField();
        DMLabel2 = new javax.swing.JLabel();
        DMInput2 = new javax.swing.JTextField();
        DMLabel3 = new javax.swing.JLabel();
        DMCheckBox = new javax.swing.JCheckBox();
        DSMLabel1 = new javax.swing.JLabel();
        DSMInput1 = new javax.swing.JTextField();
        DEPLabel3 = new javax.swing.JLabel();
        DSMInput2 = new javax.swing.JTextField();
        DEPLabel4 = new javax.swing.JLabel();
        DSMCheckBox = new javax.swing.JCheckBox();
        SFPLabel1 = new javax.swing.JLabel();
        SFInput1 = new javax.swing.JTextField();
        FCPLabel2 = new javax.swing.JLabel();
        SFCheckBox = new javax.swing.JCheckBox();
        CPSDLabel1 = new javax.swing.JLabel();
        CPSDInput1 = new javax.swing.JTextField();
        DEPCLabel2 = new javax.swing.JLabel();
        CPSDCheckBox = new javax.swing.JCheckBox();
        GlobalIndexNameComboBox = new javax.swing.JComboBox(LLib.getConceptName());
        PHGLabel = new javax.swing.JLabel();
        ImagePathLayeredPane = new javax.swing.JLayeredPane();
        ImagePathInput = new javax.swing.JTextField();
        ImagePathButton = new javax.swing.JButton();
        ImagePreviewLabel = new javax.swing.JLabel();
        ImagePreviewButton = new javax.swing.JButton();
        EyeLabel1 = new javax.swing.JLabel();
        AcquisitionSaveButton = new javax.swing.JButton();
        EyeLayeredPane = new javax.swing.JLayeredPane();
        LeftEyeRadioButton = new javax.swing.JRadioButton();
        RightEyeRadioButton = new javax.swing.JRadioButton();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jLayeredPane4 = new javax.swing.JLayeredPane();
        StudyNameLabel1 = new javax.swing.JLabel();
        AcquisitionNameInput = new javax.swing.JTextField();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        WorklistTree = new javax.swing.JTree(topWorklist);
        jScrollPane5 = new javax.swing.JScrollPane();
        PatientTree = new javax.swing.JTree(topPatient);
        PatientSearchLabel = new javax.swing.JLabel();

        HCERegisterDialog.setTitle("Actualización de la lista de pacientes citados");
        HCERegisterDialog.setSize(400, 250);
        HCERegisterDialog.setResizable(false);

        UserLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        UserLabel.setText("Usuario");

        PasswordLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PasswordLabel.setText("Contraseña");

        GoButton.setText("Acceder");
        GoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UpdateListButtonClick(evt);
            }
        });

        ProgressTextPane.setFont(new java.awt.Font("Tahoma", 1, 8)); // NOI18N
        ProgressTextPane.setText("SITUACIÓN DE LA CONEXIÓN:");
        ProgressTextPane.setFocusable(false);
        ProgressScrollPane.setViewportView(ProgressTextPane);

        javax.swing.GroupLayout HCERegisterDialogLayout = new javax.swing.GroupLayout(HCERegisterDialog.getContentPane());
        HCERegisterDialog.getContentPane().setLayout(HCERegisterDialogLayout);
        HCERegisterDialogLayout.setHorizontalGroup(
            HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(HCERegisterDialogLayout.createSequentialGroup()
                .addGroup(HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, HCERegisterDialogLayout.createSequentialGroup()
                        .addContainerGap(302, Short.MAX_VALUE)
                        .addComponent(GoButton))
                    .addGroup(HCERegisterDialogLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ProgressScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                            .addGroup(HCERegisterDialogLayout.createSequentialGroup()
                                .addGroup(HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(UserLabel)
                                    .addComponent(PasswordLabel))
                                .addGap(69, 69, 69)
                                .addGroup(HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(UserInput, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                                    .addComponent(PasswordInput, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))))))
                .addContainerGap())
        );
        HCERegisterDialogLayout.setVerticalGroup(
            HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, HCERegisterDialogLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(UserLabel)
                    .addComponent(UserInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(HCERegisterDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PasswordLabel)
                    .addComponent(PasswordInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ProgressScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(GoButton)
                .addGap(18, 18, 18))
        );

        imageDialog.setTitle("Imagen completa");
        imageDialog.setAlwaysOnTop(true);
        imageDialog.setMinimumSize(new java.awt.Dimension(500, 500));
        imageDialog.setResizable(false);

        ImageLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        imageDialog.getContentPane().add(ImageLabel, java.awt.BorderLayout.CENTER);

        Worklist.setTitle("Lista de trabajo");
        Worklist.setAlwaysOnTop(true);
        Worklist.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        WorklistDate_WF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        WorklistDate_WF.setText("Servidor de worklist seleccionado");

        RefreshButton_WF.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        RefreshButton_WF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Software Images/Backgrounds/refresh_mini.png"))); // NOI18N
        RefreshButton_WF.setText("Actualizar lista de trabajo");
        RefreshButton_WF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RefreshButton_WFActionPerformed(evt);
            }
        });

        //WorklistLayeredPane.setSize(WorklistTable.getWidth()+10, WorklistTable.getHeight()+10);
        WorklistLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Lista de trabajo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        PatientIdLabel_WF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PatientIdLabel_WF.setText("Id paciente");
        PatientIdLabel_WF.setBounds(390, 20, 130, 20);
        WorklistLayeredPane.add(PatientIdLabel_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        PatientIdInput_WF.setBounds(540, 20, 170, 25);
        WorklistLayeredPane.add(PatientIdInput_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientNameLabel_WF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PatientNameLabel_WF.setText("Nombre de paciente");
        PatientNameLabel_WF.setBounds(390, 50, 130, 20);
        WorklistLayeredPane.add(PatientNameLabel_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        PatientNameInput_WF.setBounds(540, 50, 170, 25);
        WorklistLayeredPane.add(PatientNameInput_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AccessNumberLabel_WF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        AccessNumberLabel_WF.setText("Número de acceso");
        AccessNumberLabel_WF.setBounds(390, 80, 130, 20);
        WorklistLayeredPane.add(AccessNumberLabel_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        AccessNumberInput_WF.setBounds(540, 80, 170, 25);
        WorklistLayeredPane.add(AccessNumberInput_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StudyDescriptionLabel_WF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StudyDescriptionLabel_WF.setText("Descripción del estudio");
        StudyDescriptionLabel_WF.setBounds(390, 110, 130, 20);
        WorklistLayeredPane.add(StudyDescriptionLabel_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        StudyDescriptionInput_WF.setBounds(540, 110, 170, 25);
        WorklistLayeredPane.add(StudyDescriptionInput_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        WorklistDateLabel_WF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        WorklistDateLabel_WF.setText("Fecha de búsqueda");
        WorklistDateLabel_WF.setBounds(10, 20, 130, 20);
        WorklistLayeredPane.add(WorklistDateLabel_WF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        WorklistDateButtonGroup.add(WorklistDate_Radio1);
        WorklistDate_Radio1.setSelected(true);
        WorklistDate_Radio1.setText("Hoy");
        WorklistDate_Radio1.setBounds(150, 20, 150, 30);
        WorklistLayeredPane.add(WorklistDate_Radio1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        WorklistDateButtonGroup.add(WorklistDate_Radio2);
        WorklistDate_Radio2.setText("Los últimos 7 días");
        WorklistDate_Radio2.setBounds(150, 50, 170, 30);
        WorklistLayeredPane.add(WorklistDate_Radio2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        WorklistDateButtonGroup.add(WorklistDate_Radio3);
        WorklistDate_Radio3.setText("Todos");
        WorklistDate_Radio3.setBounds(150, 80, 160, 30);
        WorklistLayeredPane.add(WorklistDate_Radio3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        WorklistXTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        WorklistXTable.setColumnControl(null);
        WorklistXTable.setEditable(false);
        WorklistXTable.getTableHeader().setReorderingAllowed(false);
        WorklistXTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ClickWorklistXTable(evt);
            }
        });
        jScrollPane3.setViewportView(WorklistXTable);

        javax.swing.GroupLayout WorklistLayout = new javax.swing.GroupLayout(Worklist.getContentPane());
        Worklist.getContentPane().setLayout(WorklistLayout);
        WorklistLayout.setHorizontalGroup(
            WorklistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(WorklistLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(WorklistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1036, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, WorklistLayout.createSequentialGroup()
                        .addComponent(WorklistLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(WorklistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(WorklistDate_WF, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                            .addComponent(RefreshButton_WF, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                            .addComponent(selectedServerComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 298, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, WorklistLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        WorklistLayout.setVerticalGroup(
            WorklistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(WorklistLayout.createSequentialGroup()
                .addGroup(WorklistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(WorklistLayout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(WorklistDate_WF, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(selectedServerComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(RefreshButton_WF, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(WorklistLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(WorklistLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        ReferralNote.setTitle("¿Desea añadir el estudio a la lista de trabajo?");
        ReferralNote.setAlwaysOnTop(true);
        ReferralNote.setMinimumSize(new java.awt.Dimension(500, 650));
        ReferralNote.setResizable(false);

        PatientLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        PatientLabel.setText("Paciente");
        PatientLabel.setBounds(40, 0, 150, 20);
        ReferralDataLayeredPane.add(PatientLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientIdLabel.setText("Identificador");
        PatientIdLabel.setBounds(40, 30, 150, 30);
        ReferralDataLayeredPane.add(PatientIdLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientIdTextField.setEditable(false);
        PatientIdTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientIdTextFieldActionPerformed(evt);
            }
        });
        PatientIdTextField.setBounds(200, 30, 250, 25);
        ReferralDataLayeredPane.add(PatientIdTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientNameLabel.setText("Nombre");
        PatientNameLabel.setBounds(40, 60, 150, 30);
        ReferralDataLayeredPane.add(PatientNameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientNameTextField.setEditable(false);
        PatientNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientNameTextFieldActionPerformed(evt);
            }
        });
        PatientNameTextField.setBounds(200, 60, 250, 25);
        ReferralDataLayeredPane.add(PatientNameTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientSurNameLabel.setText("Apellidos");
        PatientSurNameLabel.setBounds(40, 90, 150, 30);
        ReferralDataLayeredPane.add(PatientSurNameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientSurNameTextField.setEditable(false);
        PatientSurNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientSurNameTextFieldActionPerformed(evt);
            }
        });
        PatientSurNameTextField.setBounds(200, 90, 250, 25);
        ReferralDataLayeredPane.add(PatientSurNameTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientBirthDateLabel.setText("Fecha de nacimiento");
        PatientBirthDateLabel.setBounds(40, 120, 150, 30);
        ReferralDataLayeredPane.add(PatientBirthDateLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientBirthDateTextField.setEditable(false);
        PatientBirthDateTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientBirthDateTextFieldActionPerformed(evt);
            }
        });
        PatientBirthDateTextField.setBounds(200, 120, 250, 25);
        ReferralDataLayeredPane.add(PatientBirthDateTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Procedure.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Procedure.setText("Prueba solicitada");
        Procedure.setBounds(40, 180, 150, 20);
        ReferralDataLayeredPane.add(Procedure, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RequestingPhysicianLabel.setText("Facultativo solicitante");
        RequestingPhysicianLabel.setBounds(40, 210, 180, 30);
        ReferralDataLayeredPane.add(RequestingPhysicianLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RequestingPhysicianTextField.setEditable(false);
        RequestingPhysicianTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RequestingPhysicianTextFieldActionPerformed(evt);
            }
        });
        RequestingPhysicianTextField.setBounds(200, 210, 250, 25);
        ReferralDataLayeredPane.add(RequestingPhysicianTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RequestedProcedureDescriptionLabel.setText("Descripción de la prueba");
        RequestedProcedureDescriptionLabel.setBounds(40, 240, 180, 30);
        ReferralDataLayeredPane.add(RequestedProcedureDescriptionLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RequestedProcedureDescriptionTextField.setEditable(false);
        RequestedProcedureDescriptionTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RequestedProcedureDescriptionTextFieldActionPerformed(evt);
            }
        });
        RequestedProcedureDescriptionTextField.setBounds(200, 240, 250, 25);
        ReferralDataLayeredPane.add(RequestedProcedureDescriptionTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ScheduledProcedureStepDescriptionLabel.setText("Descripción del proceso");
        ScheduledProcedureStepDescriptionLabel.setBounds(40, 270, 180, 30);
        ReferralDataLayeredPane.add(ScheduledProcedureStepDescriptionLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ScheduledProcedureStepDescriptionTextField.setEditable(false);
        ScheduledProcedureStepDescriptionTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ScheduledProcedureStepDescriptionTextFieldActionPerformed(evt);
            }
        });
        ScheduledProcedureStepDescriptionTextField.setBounds(200, 270, 250, 25);
        ReferralDataLayeredPane.add(ScheduledProcedureStepDescriptionTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestPatternLabel.setText("Patrón de la prueba");
        TestPatternLabel.setBounds(40, 300, 180, 30);
        ReferralDataLayeredPane.add(TestPatternLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestPatternTextField.setEditable(false);
        TestPatternTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TestPatternTextFieldActionPerformed(evt);
            }
        });
        TestPatternTextField.setBounds(200, 300, 250, 25);
        ReferralDataLayeredPane.add(TestPatternTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestStrategyLabel.setText("Estrategia de la prueba");
        TestStrategyLabel.setBounds(40, 330, 180, 30);
        ReferralDataLayeredPane.add(TestStrategyLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestStrategyTextField.setEditable(false);
        TestStrategyTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TestStrategyTextFieldActionPerformed(evt);
            }
        });
        TestStrategyTextField.setBounds(200, 330, 250, 25);
        ReferralDataLayeredPane.add(TestStrategyTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestModeLabel.setText("Modo de la prueba");
        TestModeLabel.setBounds(40, 360, 180, 30);
        ReferralDataLayeredPane.add(TestModeLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestModeTextField.setEditable(false);
        TestModeTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TestModeTextFieldActionPerformed(evt);
            }
        });
        TestModeTextField.setBounds(200, 360, 250, 25);
        ReferralDataLayeredPane.add(TestModeTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ScheduledProcedureStartDateLabel.setText("Fecha prevista comienzo");
        ScheduledProcedureStartDateLabel.setBounds(40, 390, 180, 30);
        ReferralDataLayeredPane.add(ScheduledProcedureStartDateLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ScheduledProcedureStartDateTextField.setEditable(false);
        ScheduledProcedureStartDateTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ScheduledProcedureStartDateTextFieldActionPerformed(evt);
            }
        });
        ScheduledProcedureStartDateTextField.setBounds(200, 390, 250, 25);
        ReferralDataLayeredPane.add(ScheduledProcedureStartDateTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ScheduledProcedureStartTimeLabel.setText("Hora prevista comienzo");
        ScheduledProcedureStartTimeLabel.setBounds(40, 420, 180, 30);
        ReferralDataLayeredPane.add(ScheduledProcedureStartTimeLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ScheduledProcedureStartTimeTextField.setEditable(false);
        ScheduledProcedureStartTimeTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ScheduledProcedureStartTimeTextFieldActionPerformed(evt);
            }
        });
        ScheduledProcedureStartTimeTextField.setBounds(200, 420, 250, 25);
        ReferralDataLayeredPane.add(ScheduledProcedureStartTimeTextField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PhysicianLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        PhysicianLabel.setText("Realizador de la prueba");
        PhysicianLabel.setBounds(40, 480, 150, 30);
        ReferralDataLayeredPane.add(PhysicianLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PerformingPhysicianNameComboBox1.setBounds(200, 480, 250, 25);
        ReferralDataLayeredPane.add(PerformingPhysicianNameComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientSexLabel.setText("Sexo");
        PatientSexLabel.setBounds(40, 150, 150, 30);
        ReferralDataLayeredPane.add(PatientSexLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientSexField.setEditable(false);
        PatientSexField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientSexFieldActionPerformed(evt);
            }
        });
        PatientSexField.setBounds(200, 150, 250, 25);
        ReferralDataLayeredPane.add(PatientSexField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        newReferralNoteButton.setText("Cancelar");
        newReferralNoteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newReferralNoteButtonActionPerformed(evt);
            }
        });

        newReferralNoteButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        newReferralNoteButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Software Images/Backgrounds/Notes_mini.png"))); // NOI18N
        newReferralNoteButton1.setText("Añadir a la lista de trabajo");
        newReferralNoteButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newReferralNoteButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ReferralNoteLayout = new javax.swing.GroupLayout(ReferralNote.getContentPane());
        ReferralNote.getContentPane().setLayout(ReferralNoteLayout);
        ReferralNoteLayout.setHorizontalGroup(
            ReferralNoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ReferralNoteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ReferralNoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ReferralDataLayeredPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                    .addGroup(ReferralNoteLayout.createSequentialGroup()
                        .addComponent(newReferralNoteButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 108, Short.MAX_VALUE)
                        .addComponent(newReferralNoteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        ReferralNoteLayout.setVerticalGroup(
            ReferralNoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ReferralNoteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ReferralDataLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(ReferralNoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newReferralNoteButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(newReferralNoteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        EyeDilatationLayeredPane1.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.shadow"));
        EyeDilatationLayeredPane1.setForeground(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow"));

        DilatationRadioButton1.setText("Sí");
        DilatationRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DilatationRadioButton1ActionPerformed(evt);
            }
        });
        DilatationRadioButton1.setBounds(20, 0, 40, 23);
        EyeDilatationLayeredPane1.add(DilatationRadioButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DilatationRadioButton3.setText("No");
        DilatationRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DilatationRadioButton3ActionPerformed(evt);
            }
        });
        DilatationRadioButton3.setBounds(70, 0, 40, 20);
        EyeDilatationLayeredPane1.add(DilatationRadioButton3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ErrorDialog.setTitle("MENSAJE DE ERROR");
        ErrorDialog.setLocationRelativeTo(this);
        ErrorDialog.setSize(400, 120);
        ErrorDialog.setAlwaysOnTop(true);
        ErrorDialog.setResizable(false);

        jScrollPane6.setViewportView(ErrorPane);

        javax.swing.GroupLayout ErrorDialogLayout = new javax.swing.GroupLayout(ErrorDialog.getContentPane());
        ErrorDialog.getContentPane().setLayout(ErrorDialogLayout);
        ErrorDialogLayout.setHorizontalGroup(
            ErrorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ErrorDialogLayout.createSequentialGroup()
                .addContainerGap(87, Short.MAX_VALUE)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        ErrorDialogLayout.setVerticalGroup(
            ErrorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ErrorDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        Send.setTitle("Envío de imágenes al servidor");
        Send.setAlwaysOnTop(true);
        Send.setMinimumSize(new java.awt.Dimension(1000, 500));

        dcmsndTable.setAutoCreateRowSorter(true);
        dcmsndTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Nombre adquisición", "Nombre del paciente", "Fecha del estudio", "Tiempo adquisición", "Enviado", "Tiempo enviando (ms)", "Mensaje"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Long.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        dcmsndTable.setColumnSelectionAllowed(true);
        jScrollPane7.setViewportView(dcmsndTable);
        dcmsndTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        dcmsndTable.getColumnModel().getColumn(0).setPreferredWidth(100);
        dcmsndTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        dcmsndTable.getColumnModel().getColumn(2).setMinWidth(90);
        dcmsndTable.getColumnModel().getColumn(3).setMinWidth(90);
        dcmsndTable.getColumnModel().getColumn(5).setMinWidth(110);
        dcmsndTable.getColumnModel().getColumn(6).setMinWidth(350);
        /*dcmsndTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                for( int i = 0; i < listSended.size(); i++) {
                    Integer s = (Integer) listSended.get(i);
                    dcmsndTable.getSelectionModel().removeSelectionInterval(s, s);
                }
            }
        });*/

        dcmSndButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        dcmSndButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Software Images/Backgrounds/Send_mini.png"))); // NOI18N
        dcmSndButton.setText("Enviar adquisiciones seleccionadas");
        dcmSndButton.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        dcmSndButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dcmSndButtonActionPerformed(evt);
            }
        });

        dcmDeleteButton.setText("Eliminar adquisiciones seleccionadas");
        dcmDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dcmDeleteButtonActionPerformed(evt);
            }
        });

        SelectAllButton.setText("Seleccionar/ Deseleccionar todas");
        SelectAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectAllButtonActionPerformed(evt);
            }
        });

        dcmSndBuffer.setColumns(20);
        dcmSndBuffer.setEditable(false);
        dcmSndBuffer.setRows(5);
        jScrollPane8.setViewportView(dcmSndBuffer);

        SendingLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        SendingLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        SendingLabel.setText("Envío de imágenes");

        SelectedServerLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SelectedServerLabel.setText("Selección del servidor de destino");

        javax.swing.GroupLayout SendLayout = new javax.swing.GroupLayout(Send.getContentPane());
        Send.getContentPane().setLayout(SendLayout);
        SendLayout.setHorizontalGroup(
            SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SendLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 895, Short.MAX_VALUE)
                    .addGroup(SendLayout.createSequentialGroup()
                        .addComponent(SelectAllButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 268, Short.MAX_VALUE)
                        .addComponent(SelectedServerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(selectedServerComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(SendLayout.createSequentialGroup()
                        .addGap(596, 596, 596)
                        .addComponent(SendingLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SendingProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(SendLayout.createSequentialGroup()
                        .addGroup(SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dcmSndButton, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
                            .addComponent(dcmDeleteButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)))
                .addContainerGap())
        );
        SendLayout.setVerticalGroup(
            SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SendLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SelectAllButton)
                    .addComponent(SelectedServerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectedServerComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SendLayout.createSequentialGroup()
                        .addComponent(dcmSndButton, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(dcmDeleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(SendLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(SendingProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(SendLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(SendingLabel)))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Panel de Dicomización");
        setMinimumSize(new java.awt.Dimension(800, 600));

        PatientListLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        PatientListLabel.setText("Historial de Pacientes");

        PatientListRefreshButton.setText("Consultar worklist");
        PatientListRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientListRefreshClick(evt);
            }
        });

        PatientSearchInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                KeyReleasedFilter(evt);
            }
        });

        RemovePatientButton.setText("Eliminar nodo seleccionado");
        RemovePatientButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RemovePatientButtonCreatePatient(evt);
            }
        });

        SendButton.setText("Enviar estudios DICOM");
        SendButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SendButtonClick(evt);
            }
        });

        HCE_checkLabel.setFont(new java.awt.Font("Tahoma", 3, 10)); // NOI18N

        SexLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SexLabel.setText("Sexo");
        SexLabel.setBounds(40, 160, 230, 20);
        patientLayeredPane.add(SexLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientCommentsLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PatientCommentsLabel.setText("Comentarios generales del paciente");
        PatientCommentsLabel.setBounds(40, 195, 230, 20);
        patientLayeredPane.add(PatientCommentsLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //PatientCommentsTextArea.setDocument(new libraries.JTextFieldLimit(PatientCommentsTextAreaLenght));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(PatientCommentsTextAreaLenght);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        PatientCommentsTextArea.setDocument(jtff);
        PatientCommentsTextArea.setColumns(20);
        PatientCommentsTextArea.setRows(5);
        jScrollPane2.setViewportView(PatientCommentsTextArea);

        jScrollPane2.setBounds(280, 190, 220, 160);
        patientLayeredPane.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PatientSaveButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        PatientSaveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Software Images/Backgrounds/Save_mini.png"))); // NOI18N
        PatientSaveButton.setText("Guardar paciente");
        PatientSaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PatientSaveButtonActionPerformed(evt);
            }
        });
        PatientSaveButton.setBounds(280, 360, 220, 50);
        patientLayeredPane.add(PatientSaveButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SexButtonGroup.add(SexM_Radio);
        SexM_Radio.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SexM_Radio.setText("Masculino");
        SexM_Radio.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        SexM_Radio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SexM_RadioActionPerformed(evt);
            }
        });
        SexM_Radio.setBounds(0, 0, 100, 25);
        ButtonsLayeredPane.add(SexM_Radio, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SexButtonGroup.add(SexF_Radio);
        SexF_Radio.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SexF_Radio.setText("Femenino");
        SexF_Radio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SexF_RadioActionPerformed(evt);
            }
        });
        SexF_Radio.setBounds(120, 0, 110, 25);
        ButtonsLayeredPane.add(SexF_Radio, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ButtonsLayeredPane.setBounds(280, 160, 230, 24);
        patientLayeredPane.add(ButtonsLayeredPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BirthDateInput.setToolTipText("");
        BirthDateInput.setFormats(dateFormat);
        BirthDateInput.setNextFocusableComponent(SexM_Radio);
        BirthDateInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BirthDateInputActionPerformed(evt);
            }
        });
        BirthDateInput.setBounds(280, 125, 220, 25);
        patientLayeredPane.add(BirthDateInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BirthDateLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BirthDateLabel.setText("Fecha de nacimiento");
        BirthDateLabel.setBounds(40, 125, 230, 20);
        patientLayeredPane.add(BirthDateLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SurnameLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SurnameLabel.setText("Apellidos");
        SurnameLabel.setBounds(40, 90, 230, 20);
        patientLayeredPane.add(SurnameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //SurnameInput.setDocument(new libraries.JTextFieldLimit(SurnameInputLenght));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA);
        jtff.setLimit(SurnameInputLenght);
        jtff.setSpaceAccepted(true);
        SurnameInput.setDocument(jtff);
        SurnameInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SurnameInputActionPerformed(evt);
            }
        });
        SurnameInput.setBounds(280, 90, 220, 25);
        patientLayeredPane.add(SurnameInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //NameInput.setDocument(new libraries.JTextFieldLimit(NameInputLenght));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA);
        jtff.setLimit(NameInputLenght);
        jtff.setSpaceAccepted(true);
        NameInput.setDocument(jtff);
        NameInput.setBounds(280, 55, 220, 25);
        patientLayeredPane.add(NameInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NameLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        NameLabel.setText("Nombre");
        NameLabel.setBounds(40, 55, 230, 20);
        patientLayeredPane.add(NameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        HCELabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        HCELabel.setText("Nº Historia Clínica Electrónica");
        HCELabel.setBounds(40, 20, 230, 20);
        patientLayeredPane.add(HCELabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //HCEInput.setDocument(new libraries.JTextFieldLimit(HCEInputLenght,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setLimit(HCEInputLenght);
        HCEInput.setDocument(jtff);
        HCEInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HCEInputActionPerformed(evt);
            }
        });
        HCEInput.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                HCEInputFocusLost(evt);
            }
        });
        HCEInput.setBounds(280, 20, 220, 25);
        patientLayeredPane.add(HCEInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout DemographicPanelLayout = new javax.swing.GroupLayout(DemographicPanel);
        DemographicPanel.setLayout(DemographicPanelLayout);
        DemographicPanelLayout.setHorizontalGroup(
            DemographicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DemographicPanelLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(patientLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 542, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(HCE_checkLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                .addContainerGap())
        );
        DemographicPanelLayout.setVerticalGroup(
            DemographicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DemographicPanelLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(DemographicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(patientLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(HCE_checkLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(229, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Datos demográficos del paciente", DemographicPanel);

        ClinicPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        ClinicPanel.setEnabled(false);
        ClinicPanel.setPreferredSize(new java.awt.Dimension(500, 621));

        StudyNameLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StudyNameLabel.setText("Nombre del estudio");

        StudyNameInput.setEditable(false);

        StudyDateLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StudyDateLabel.setText("Fecha de estudio");

        StudyDateInput.setFormats(dateFormat);
        StudyDateInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StudyDateInputActionPerformed(evt);
            }
        });

        ClinicDataLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos clínicos previos a la prueba", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        RxLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxLabel1.setText("Rx (Refracción)");
        RxLabel1.setBounds(20, 70, 100, 20);
        ClinicDataLayeredPane.add(RxLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxPane1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, java.awt.Color.white, null, null));
        RxRightEyeLabel.setBounds(90, 0, 100, 0);
        RxPane1.add(RxRightEyeLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxLeftEyeLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxLeftEyeLabel.setText("Ojo Derecho:");
        RxLeftEyeLabel.setBounds(90, 10, 100, 15);
        RxPane1.add(RxLeftEyeLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator3.setBounds(0, 30, 520, 10);
        RxPane1.add(jSeparator3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator4.setBounds(260, 0, 10, 70);
        RxPane1.add(jSeparator4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //RxRightEyeInput1.setDocument(new libraries.JTextFieldLimit(RxRightEyeInput1Lenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(RxRightEyeInput1Lenght);
        jtff.setMaxValue(RxSphericalMaxValue);
        RxRightEyeInput1.setDocument(jtff);
        RxRightEyeInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RxRightEyeInput1ActionPerformed(evt);
            }
        });
        RxRightEyeInput1.setBounds(10, 40, 40, 25);
        RxPane1.add(RxRightEyeInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxRightEyeLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxRightEyeLabel1.setText("Esfera");
        RxRightEyeLabel1.setBounds(60, 40, 50, 20);
        RxPane1.add(RxRightEyeLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //RxRightEyeInput2.setDocument(new libraries.JTextFieldLimit(RxRightEyeInput2Lenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(RxRightEyeInput2Lenght);
        jtff.setMaxValue(RxCilinderMaxValue);
        RxRightEyeInput2.setDocument(jtff);
        RxRightEyeInput2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RxRightEyeInput2ActionPerformed(evt);
            }
        });
        RxRightEyeInput2.setBounds(100, 40, 40, 25);
        RxPane1.add(RxRightEyeInput2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxRightEyeLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxRightEyeLabel2.setText(" Cilindro  x");
        RxRightEyeLabel2.setBounds(140, 40, 70, 20);
        RxPane1.add(RxRightEyeLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //RxRightEyeInput3.setDocument(new libraries.JTextFieldLimit(RxRightEyeInput3Lenght,false,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setLimit(RxRightEyeInput3Lenght);
        jtff.setMaxValue(cylinderAxisMaxValue);
        RxRightEyeInput3.setDocument(jtff);
        RxRightEyeInput3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RxRightEyeInput3ActionPerformed(evt);
            }
        });
        RxRightEyeInput3.setBounds(200, 40, 50, 25);
        RxPane1.add(RxRightEyeInput3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //RxLeftEyeInput1.setDocument(new libraries.JTextFieldLimit(RxLeftEyeInput1Lenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(RxLeftEyeInput1Lenght);
        jtff.setMaxValue(RxSphericalMaxValue);
        RxLeftEyeInput1.setDocument(jtff);
        RxLeftEyeInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RxLeftEyeInput1ActionPerformed(evt);
            }
        });
        RxLeftEyeInput1.setBounds(270, 40, 40, 25);
        RxPane1.add(RxLeftEyeInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxLeftEyeLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxLeftEyeLabel1.setText("Esfera");
        RxLeftEyeLabel1.setBounds(320, 40, 60, 20);
        RxPane1.add(RxLeftEyeLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //RxLeftEyeInput2.setDocument(new libraries.JTextFieldLimit(RxLeftEyeInput2Lenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(RxLeftEyeInput2Lenght);
        jtff.setMaxValue(RxCilinderMaxValue);
        RxLeftEyeInput2.setDocument(jtff);
        RxLeftEyeInput2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RxLeftEyeInput2ActionPerformed(evt);
            }
        });
        RxLeftEyeInput2.setBounds(360, 40, 40, 25);
        RxPane1.add(RxLeftEyeInput2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxLeftEyeLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxLeftEyeLabel2.setText(" Cilindro  x");
        RxLeftEyeLabel2.setBounds(400, 40, 70, 20);
        RxPane1.add(RxLeftEyeLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //RxLeftEyeInput3.setDocument(new libraries.JTextFieldLimit(RxLeftEyeInput3Lenght,false,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setLimit(RxLeftEyeInput3Lenght);
        jtff.setMaxValue(cylinderAxisMaxValue);
        RxLeftEyeInput3.setDocument(jtff);
        RxLeftEyeInput3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RxLeftEyeInput3ActionPerformed(evt);
            }
        });
        RxLeftEyeInput3.setBounds(460, 40, 50, 25);
        RxPane1.add(RxLeftEyeInput3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxLeftEyeLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RxLeftEyeLabel3.setText("Ojo Izquierdo:");
        RxLeftEyeLabel3.setBounds(340, 10, 100, 15);
        RxPane1.add(RxLeftEyeLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        RxPane1.setBounds(110, 30, 520, 70);
        ClinicDataLayeredPane.add(RxPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Definicion del tipo de prueba", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        TestPatternsLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TestPatternsLabel.setText("Patrón de la prueba");
        TestPatternsLabel.setBounds(20, 100, 120, 15);
        jLayeredPane1.add(TestPatternsLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        TestPatternsComboBox.setBounds(340, 100, 290, 20);
        jLayeredPane1.add(TestPatternsComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestModesLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TestModesLabel.setText("Modo de la prueba");
        TestModesLabel.setBounds(20, 130, 120, 15);
        jLayeredPane1.add(TestModesLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestModesComboBox.setBounds(340, 130, 290, 20);
        jLayeredPane1.add(TestModesComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        studyCommentsLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        studyCommentsLabel.setText("Comentarios del estudio");
        studyCommentsLabel.setBounds(20, 190, 170, 15);
        jLayeredPane1.add(studyCommentsLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestStrategyComboBox.setBounds(340, 160, 290, 20);
        jLayeredPane1.add(TestStrategyComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PerformingPhysicianLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PerformingPhysicianLabel.setText("Realizador de la prueba");
        PerformingPhysicianLabel.setBounds(20, 70, 130, 15);
        jLayeredPane1.add(PerformingPhysicianLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PerformingPhysicianNameComboBox.setBounds(340, 70, 290, 20);
        jLayeredPane1.add(PerformingPhysicianNameComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //StudyCommentsTextArea.setDocument(new libraries.JTextFieldLimit(StudyCommentsTextAreaLenght));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(StudyCommentsTextAreaLenght);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        StudyCommentsTextArea.setDocument(jtff);
        StudyCommentsTextArea.setColumns(20);
        StudyCommentsTextArea.setRows(5);
        StudyCommentsTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane9.setViewportView(StudyCommentsTextArea);

        jScrollPane9.setBounds(340, 190, 290, 60);
        jLayeredPane1.add(jScrollPane9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestStrategyLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TestStrategyLabel1.setText("Estrategia de la prueba");
        TestStrategyLabel1.setBounds(20, 160, 140, 15);
        jLayeredPane1.add(TestStrategyLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StudyDescriptionLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StudyDescriptionLabel.setText("Comentarios del especialista");
        StudyDescriptionLabel.setBounds(20, 20, 170, 20);
        jLayeredPane1.add(StudyDescriptionLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StudyDescriptionTextArea.setColumns(20);
        StudyDescriptionTextArea.setEditable(false);
        StudyDescriptionTextArea.setRows(5);
        StudyDescriptionTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane10.setViewportView(StudyDescriptionTextArea);

        jScrollPane10.setBounds(340, 20, 290, 40);
        jLayeredPane1.add(jScrollPane10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StudySaveButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        StudySaveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Software Images/Backgrounds/Save_mini.png"))); // NOI18N
        StudySaveButton.setText("Guardar estudio");
        StudySaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StudySaveButtonActionPerformed(evt);
            }
        });

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Configuracion del campimetro", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        FixationStrategyLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FixationStrategyLabel.setText("Monitor de fijación");
        FixationStrategyLabel.setBounds(10, 30, 120, 15);
        jLayeredPane2.add(FixationStrategyLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FixationStrategyComboBox.setBounds(140, 30, 170, 20);
        jLayeredPane2.add(FixationStrategyComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
        FixationStrategyComboBox.setSelectedItem(defaultFixationStrategy);

        FixationTargetLabel.setVisible(false);
        FixationTargetLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FixationTargetLabel.setText("Objetivo de fijación");
        FixationTargetLabel.setEnabled(false);
        FixationTargetLabel.setBounds(330, 30, 120, 15);
        jLayeredPane2.add(FixationTargetLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FixationTargetComboBox.setVisible(false);
        FixationTargetComboBox.setBounds(460, 30, 170, 20);
        jLayeredPane2.add(FixationTargetComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StimulusLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StimulusLabel.setText("Estímulo");
        StimulusLabel.setBounds(10, 60, 120, 15);
        jLayeredPane2.add(StimulusLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StimulusLayeredPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        StimulusLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StimulusLabel2.setText("Tamaño");
        StimulusLabel2.setBounds(10, 10, 50, 20);
        StimulusLayeredPane.add(StimulusLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StimulusComboBox1.setBounds(60, 10, 100, 20);
        StimulusLayeredPane.add(StimulusComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        StimulusComboBox1.setSelectedItem(defaultStimulusSize);

        StimulusLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StimulusLabel3.setText("Color");
        StimulusLabel3.setBounds(10, 40, 40, 20);
        StimulusLayeredPane.add(StimulusLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StimulusComboBox2.setBounds(60, 40, 100, 20);
        StimulusLayeredPane.add(StimulusComboBox2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        StimulusComboBox2.setSelectedItem(defaultStimulusColor);

        StimulusLayeredPane.setBounds(140, 60, 170, 70);
        jLayeredPane2.add(StimulusLayeredPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackgroundLuminanceLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BackgroundLuminanceLabel1.setText("Luminancia del fondo");
        BackgroundLuminanceLabel1.setBounds(330, 60, 120, 15);
        jLayeredPane2.add(BackgroundLuminanceLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackgroundLuminanceLayeredPane.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        BackgroundLuminanceLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BackgroundLuminanceLabel2.setText("ASB");
        BackgroundLuminanceLabel2.setBounds(130, 10, 30, 20);
        BackgroundLuminanceLayeredPane.add(BackgroundLuminanceLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackgroundLuminanceLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        BackgroundLuminanceLabel3.setText("Color");
        BackgroundLuminanceLabel3.setBounds(10, 40, 40, 20);
        BackgroundLuminanceLayeredPane.add(BackgroundLuminanceLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackgroundLuminanceComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackgroundLuminanceComboBox2ActionPerformed(evt);
            }
        });
        BackgroundLuminanceComboBox2.setBounds(50, 40, 110, 20);
        BackgroundLuminanceLayeredPane.add(BackgroundLuminanceComboBox2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        BackgroundLuminanceComboBox2.setSelectedItem(defaultBackgruondColor);

        BackgroundLuminanceComboBox1.setBounds(50, 10, 70, 20);
        BackgroundLuminanceLayeredPane.add(BackgroundLuminanceComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        BackgroundLuminanceComboBox1.setSelectedItem(defaultBackgruondLuminance);

        BackgroundLuminanceLayeredPane.setBounds(460, 60, 170, 70);
        jLayeredPane2.add(BackgroundLuminanceLayeredPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout ClinicPanelLayout = new javax.swing.GroupLayout(ClinicPanel);
        ClinicPanel.setLayout(ClinicPanelLayout);
        ClinicPanelLayout.setHorizontalGroup(
            ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ClinicPanelLayout.createSequentialGroup()
                .addGroup(ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ClinicPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLayeredPane1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ClinicPanelLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(StudyNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(StudyDateLabel))
                        .addGap(10, 10, 10)
                        .addGroup(ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(StudyDateInput, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(StudyNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ClinicPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(ClinicDataLayeredPane))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ClinicPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ClinicPanelLayout.createSequentialGroup()
                                .addComponent(StudySaveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(435, 435, 435))
                            .addComponent(jLayeredPane2))))
                .addGap(57, 57, 57))
        );
        ClinicPanelLayout.setVerticalGroup(
            ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ClinicPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StudyNameInput, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                    .addComponent(StudyNameLabel))
                .addGap(12, 12, 12)
                .addGroup(ClinicPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(StudyDateInput, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(StudyDateLabel))
                .addGap(10, 10, 10)
                .addComponent(ClinicDataLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(StudySaveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Datos del estudio", ClinicPanel);

        ImagePanel.setPreferredSize(new java.awt.Dimension(400, 300));

        ReliabilityLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Factores de fiabilidad", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        FixationLossesLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FixationLossesLabel.setText(" /");
        FixationLossesLabel.setBounds(200, 30, 20, 20);
        ReliabilityLayeredPane.add(FixationLossesLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //FixationLossesInput.setDocument(new libraries.JTextFieldLimit(FixationLossesInputLenght,false,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(FixationLossesInputLenght);
        jtff.setMaxValue(percentageMaxValue);
        FixationLossesInput.setDocument(jtff);
        FixationLossesInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FixationLossesInputActionPerformed(evt);
            }
        });
        FixationLossesInput.setBounds(160, 30, 40, 25);
        ReliabilityLayeredPane.add(FixationLossesInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //FixationLossesCheckedInput.setDocument(new libraries.JTextFieldLimit(FixationLossesInputLenght,false,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(FixationLossesInputLenght);
        jtff.setMaxValue(percentageMaxValue);
        FixationLossesCheckedInput.setDocument(jtff);
        FixationLossesCheckedInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FixationLossesCheckedInputActionPerformed(evt);
            }
        });
        FixationLossesCheckedInput.setBounds(210, 30, 40, 25);
        ReliabilityLayeredPane.add(FixationLossesCheckedInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FalsePositivesLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FalsePositivesLabel1.setText("Errores falsos positivos");
        FalsePositivesLabel1.setBounds(20, 130, 130, 20);
        ReliabilityLayeredPane.add(FalsePositivesLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //FalsePositivesInput.setDocument(new libraries.JTextFieldLimit(FalsePositivesInputLenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(FalsePositivesInputLenght);
        jtff.setMaxValue(percentageMaxValue);
        FalsePositivesInput.setDocument(jtff);
        FalsePositivesInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FalsePositivesInputActionPerformed(evt);
            }
        });
        FalsePositivesInput.setBounds(160, 130, 50, 25);
        ReliabilityLayeredPane.add(FalsePositivesInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FalsePositivesLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FalsePositivesLabel2.setText("%");
        FalsePositivesLabel2.setBounds(220, 130, 30, 20);
        ReliabilityLayeredPane.add(FalsePositivesLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FalseNegativesLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FalseNegativesLabel1.setText("Errores falsos negativos");
        FalseNegativesLabel1.setBounds(20, 160, 170, 20);
        ReliabilityLayeredPane.add(FalseNegativesLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //FalseNegativesInput.setDocument(new libraries.JTextFieldLimit(FalseNegativesInputLenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(FalseNegativesInputLenght);
        jtff.setMaxValue(percentageMaxValue);
        FalseNegativesInput.setDocument(jtff);
        FalseNegativesInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FalseNegativesInputActionPerformed(evt);
            }
        });
        FalseNegativesInput.setBounds(160, 160, 50, 25);
        ReliabilityLayeredPane.add(FalseNegativesInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FalseNegativesLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FalseNegativesLabel2.setText("%");
        FalseNegativesLabel2.setBounds(220, 160, 20, 20);
        ReliabilityLayeredPane.add(FalseNegativesLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FovealLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FovealLabel.setText("Foveal");
        FovealLabel.setBounds(20, 70, 60, 20);
        ReliabilityLayeredPane.add(FovealLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FovealButtonGroup.add(FovealRadioButton1);
        FovealRadioButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FovealRadioButton1.setText("Encendido");
        FovealRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FovealRadioButton1ActionPerformed(evt);
            }
        });
        FovealRadioButton1.setBounds(10, 0, 100, 25);
        FovealLayeredPane.add(FovealRadioButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FovealButtonGroup.add(FovealRadioButton2);
        FovealRadioButton2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FovealRadioButton2.setText("Apagado");
        FovealRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FovealRadioButton2ActionPerformed(evt);
            }
        });
        FovealRadioButton2.setBounds(10, 20, 100, 25);
        FovealLayeredPane.add(FovealRadioButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        FovealRadioButton2.setSelected(true);

        FovealLayeredPane.setBounds(60, 70, 110, 40);
        ReliabilityLayeredPane.add(FovealLayeredPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SensibilityLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SensibilityLabel1.setText("Sensibilidad foveal");
        SensibilityLabel1.setBounds(230, 70, 130, 20);
        ReliabilityLayeredPane.add(SensibilityLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //SensibilityInput.setDocument(new libraries.JTextFieldLimit(SensibilityInputLenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(SensibilityInputLenght);
        jtff.setMaxValue(decibelMaxValue);
        SensibilityInput.setDocument(jtff);
        SensibilityInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SensibilityInputActionPerformed(evt);
            }
        });
        SensibilityInput.setBounds(360, 70, 50, 25);
        ReliabilityLayeredPane.add(SensibilityInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SensibilityLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SensibilityLabel2.setText("dB");
        SensibilityLabel2.setBounds(420, 70, 20, 20);
        ReliabilityLayeredPane.add(SensibilityLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestDurationLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TestDurationLabel1.setText("Duración de la prueba");
        TestDurationLabel1.setBounds(20, 190, 130, 20);
        ReliabilityLayeredPane.add(TestDurationLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //TestDurationInput1.setDocument(new libraries.JTextFieldLimit(TestDurationInput1Lenght,false,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(TestDurationInput1Lenght);
        jtff.setMaxValue(minuteMaxValue);
        TestDurationInput1.setDocument(jtff);
        TestDurationInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TestDurationInput1ActionPerformed(evt);
            }
        });
        TestDurationInput1.setBounds(160, 190, 30, 25);
        ReliabilityLayeredPane.add(TestDurationInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestDurationLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TestDurationLabel2.setText("min");
        TestDurationLabel2.setBounds(200, 190, 40, 20);
        ReliabilityLayeredPane.add(TestDurationLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //TestDurationInput2.setDocument(new libraries.JTextFieldLimit(TestDurationInput2Lenght,false,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(TestDurationInput2Lenght);
        jtff.setMaxValue(minuteMaxValue);
        TestDurationInput2.setDocument(jtff);
        TestDurationInput2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TestDurationInput2ActionPerformed(evt);
            }
        });
        TestDurationInput2.setBounds(230, 190, 30, 25);
        ReliabilityLayeredPane.add(TestDurationInput2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TestDurationLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        TestDurationLabel3.setText("seg");
        TestDurationLabel3.setBounds(270, 190, 40, 20);
        ReliabilityLayeredPane.add(TestDurationLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FixationLossesLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FixationLossesLabel1.setText("Pérdidas de fijación");
        FixationLossesLabel1.setBounds(20, 30, 130, 20);
        ReliabilityLayeredPane.add(FixationLossesLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        GlobalIndicesPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Índices globales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        GlobalIndexNameLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        GlobalIndexNameLabel.setText("Nombre del indice global");
        GlobalIndexNameLabel.setBounds(10, 30, 270, 20);
        GlobalIndicesPane.add(GlobalIndexNameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        PHGComboBox.setBounds(300, 60, 340, 20);
        GlobalIndicesPane.add(PHGComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
        PHGComboBox.setSelectedItem(defaultPHG);

        DMLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DMLabel1.setText("Desviación Media (DM)");
        DMLabel1.setBounds(10, 90, 250, 20);
        GlobalIndicesPane.add(DMLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DMInput1.setDocument(new libraries.JTextFieldLimit(this,DMInput1.getName(),DMInput1Lenght,false,true,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(DMInput1Lenght);
        jtff.setMaxValue(decibelMaxValue);
        DMInput1.setDocument(jtff);
        DMInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DMInput1ActionPerformed(evt);
            }
        });
        DMInput1.setBounds(300, 90, 50, 25);
        GlobalIndicesPane.add(DMInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DMLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DMLabel2.setText("dB   P<");
        DMLabel2.setBounds(360, 90, 80, 20);
        GlobalIndicesPane.add(DMLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DMInput2.setDocument(new libraries.JTextFieldLimit(DMInput2Lenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(DMInput2Lenght);
        jtff.setMaxValue(percentageMaxValue);
        jtff.setMaxDecimal(PmaxDecimals);
        DMInput2.setDocument(jtff);
        DMInput2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DMInput2ActionPerformed(evt);
            }
        });
        DMInput2.setBounds(410, 90, 50, 25);
        GlobalIndicesPane.add(DMInput2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DMLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DMLabel3.setText("%");
        DMLabel3.setBounds(470, 90, 40, 20);
        GlobalIndicesPane.add(DMLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DMCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DMCheckBox.setText("Desviación significativa");
        DMCheckBox.setBounds(500, 90, 160, 20);
        GlobalIndicesPane.add(DMCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DSMLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DSMLabel1.setText("Desviación Estándar del Patrón (DSM)");
        DSMLabel1.setBounds(10, 120, 250, 20);
        GlobalIndicesPane.add(DSMLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DSMInput1.setDocument(new libraries.JTextFieldLimit(/*DSMInput1,*/DSMInput1Lenght,false,true,true/*,true*/));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(DSMInput1Lenght);
        jtff.setMaxValue(decibelMaxValue);
        DSMInput1.setDocument(jtff);
        DSMInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DSMInput1ActionPerformed(evt);
            }
        });
        DSMInput1.setBounds(300, 120, 50, 25);
        GlobalIndicesPane.add(DSMInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DEPLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DEPLabel3.setText("dB   P<");
        DEPLabel3.setBounds(360, 120, 70, 20);
        GlobalIndicesPane.add(DEPLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DSMInput2.setDocument(new libraries.JTextFieldLimit(DSMInput2Lenght,false,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(false);
        jtff.setLimit(DSMInput2Lenght);
        jtff.setMaxValue(percentageMaxValue);
        jtff.setMaxDecimal(PmaxDecimals);
        DSMInput2.setDocument(jtff);
        DSMInput2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DSMInput2ActionPerformed(evt);
            }
        });
        DSMInput2.setBounds(410, 120, 50, 25);
        GlobalIndicesPane.add(DSMInput2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DEPLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DEPLabel4.setText("%");
        DEPLabel4.setBounds(470, 120, 40, 20);
        GlobalIndicesPane.add(DEPLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DSMCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DSMCheckBox.setText("Desviación significativa");
        DSMCheckBox.setBounds(500, 120, 160, 20);
        GlobalIndicesPane.add(DSMCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SFPLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SFPLabel1.setText("Fluctuación a Corto Plazo (SF)");
        SFPLabel1.setBounds(10, 150, 260, 20);
        GlobalIndicesPane.add(SFPLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //SFInput1.setDocument(new libraries.JTextFieldLimit(/*SFInput1,*/SFInput1Lenght,false,true,true/*,true*/));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(SFInput1Lenght);
        jtff.setMaxValue(decibelMaxValue);
        SFInput1.setDocument(jtff);
        SFInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SFInput1ActionPerformed(evt);
            }
        });
        SFInput1.setBounds(410, 150, 50, 25);
        GlobalIndicesPane.add(SFInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        FCPLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FCPLabel2.setText("dB");
        FCPLabel2.setBounds(470, 150, 50, 20);
        GlobalIndicesPane.add(FCPLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SFCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SFCheckBox.setText("FCP Calculada");
        SFCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SFCheckBoxActionPerformed(evt);
            }
        });
        SFCheckBox.setBounds(500, 150, 130, 20);
        GlobalIndicesPane.add(SFCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
        SFCheckBox.setSelected(false);

        CPSDLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CPSDLabel1.setText("Desviación Estándar del Patrón Corregida (CPSD)");
        CPSDLabel1.setBounds(10, 180, 300, 20);
        GlobalIndicesPane.add(CPSDLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //CPSDInput1.setDocument(new libraries.JTextFieldLimit(/*CPSDInput1,*/CPSDInput1Lenght,false,true,true/*,true*/));
        jtff = new JTextFieldFilter(JTextFieldFilter.FLOAT);
        jtff.setNegativeAccepted(true);
        jtff.setLimit(CPSDInput1Lenght);
        jtff.setMaxValue(decibelMaxValue);
        CPSDInput1.setDocument(jtff);
        CPSDInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CPSDInput1ActionPerformed(evt);
            }
        });
        CPSDInput1.setBounds(410, 180, 50, 25);
        GlobalIndicesPane.add(CPSDInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DEPCLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DEPCLabel2.setText("dB");
        DEPCLabel2.setBounds(470, 180, 50, 20);
        GlobalIndicesPane.add(DEPCLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CPSDCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CPSDCheckBox.setText("DEPC Calculada");
        CPSDCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CPSDCheckBoxActionPerformed(evt);
            }
        });
        CPSDCheckBox.setBounds(500, 180, 130, 20);
        GlobalIndicesPane.add(CPSDCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
        CPSDCheckBox.setSelected(false);
        GlobalIndexNameComboBox.setBounds(300, 30, 340, 20);
        GlobalIndicesPane.add(GlobalIndexNameComboBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
        GlobalIndexNameComboBox.setSelectedItem(defaultGlobalIndexName);

        PHGLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PHGLabel.setText("Valor del indice seleccionado");
        PHGLabel.setBounds(10, 60, 270, 20);
        GlobalIndicesPane.add(PHGLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ImagePathLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Añadir imagen", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        //ImagePathInput.setDocument(new libraries.JTextFieldLimit(ImagePathInputLenght));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(ImagePathInputLenght);
        jtff.setSpaceAccepted(false);
        ImagePathInput.setDocument(jtff);
        ImagePathInput.setFocusable(false);
        ImagePathInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ImagePathInputActionPerformed(evt);
            }
        });
        ImagePathInput.setBounds(20, 30, 150, 25);
        ImagePathLayeredPane.add(ImagePathInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ImagePathButton.setText("Editar ruta");
        ImagePathButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ImagePathButtonClick(evt);
            }
        });
        ImagePathButton.setBounds(20, 60, 150, 25);
        ImagePathLayeredPane.add(ImagePathButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ImagePreviewLabel.setForeground(new java.awt.Color(204, 204, 204));
        ImagePreviewLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.lightGray, null));
        ImagePreviewLabel.setPreferredSize(new java.awt.Dimension(1024, 768));
        ImagePreviewLabel.setBounds(20, 120, 150, 180);
        ImagePathLayeredPane.add(ImagePreviewLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ImagePreviewButton.setText("Ampliar imagen");
        ImagePreviewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ImagePreviewButtonActionPerformed(evt);
            }
        });
        ImagePreviewButton.setBounds(20, 310, 150, 25);
        ImagePathLayeredPane.add(ImagePreviewButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EyeLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        EyeLabel1.setText("Vista previa de la imagen");
        EyeLabel1.setBounds(20, 100, 150, 15);
        ImagePathLayeredPane.add(EyeLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AcquisitionSaveButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        AcquisitionSaveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Software Images/Backgrounds/Save_mini.png"))); // NOI18N
        AcquisitionSaveButton.setText("Guardar adquisición");
        AcquisitionSaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AcquisitionSaveButtonActionPerformed(evt);
            }
        });

        EyeLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ojo bajo estudio", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        EyeLayeredPane.setForeground(new java.awt.Color(0, 0, 255));

        EyeButtonGroup.add(LeftEyeRadioButton);
        LeftEyeRadioButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        LeftEyeRadioButton.setSelected(true);
        LeftEyeRadioButton.setText("Izquierdo");
        LeftEyeRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LeftEyeRadioButtonActionPerformed(evt);
            }
        });
        LeftEyeRadioButton.setBounds(20, 30, 90, 25);
        EyeLayeredPane.add(LeftEyeRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EyeButtonGroup.add(RightEyeRadioButton);
        RightEyeRadioButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RightEyeRadioButton.setText("Derecho");
        RightEyeRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RightEyeRadioButtonActionPerformed(evt);
            }
        });
        RightEyeRadioButton.setBounds(20, 50, 90, 25);
        EyeLayeredPane.add(RightEyeRadioButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setBounds(30, 0, 0, 0);
        EyeLayeredPane.add(jLayeredPane3, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setBounds(-50, -50, 180, 50);
        EyeLayeredPane.add(jLayeredPane4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        StudyNameLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        StudyNameLabel1.setText("Nombre de la adquisición");

        AcquisitionNameInput.setEditable(false);

        javax.swing.GroupLayout ImagePanelLayout = new javax.swing.GroupLayout(ImagePanel);
        ImagePanel.setLayout(ImagePanelLayout);
        ImagePanelLayout.setHorizontalGroup(
            ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ImagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ImagePanelLayout.createSequentialGroup()
                        .addGroup(ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(GlobalIndicesPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE)
                            .addGroup(ImagePanelLayout.createSequentialGroup()
                                .addGroup(ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(ImagePanelLayout.createSequentialGroup()
                                        .addComponent(StudyNameLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(AcquisitionNameInput, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                                        .addGap(18, 18, 18)
                                        .addComponent(EyeLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(ReliabilityLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ImagePathLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(21, 21, 21))
                    .addGroup(ImagePanelLayout.createSequentialGroup()
                        .addComponent(AcquisitionSaveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(481, Short.MAX_VALUE))))
        );
        ImagePanelLayout.setVerticalGroup(
            ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ImagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(ImagePanelLayout.createSequentialGroup()
                        .addGroup(ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ImagePanelLayout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addGroup(ImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(StudyNameLabel1)
                                    .addComponent(AcquisitionNameInput, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE))
                                .addGap(93, 93, 93))
                            .addComponent(EyeLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(ReliabilityLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(ImagePathLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(GlobalIndicesPane, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(AcquisitionSaveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Datos + Imágenes de las adquisiciones", ImagePanel);

        WorklistTree.setRootVisible(false);
        WorklistTree.setModel(WorklistTree.getModel());
        WorklistTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ClickWorklistTree(evt);
            }
        });
        jScrollPane1.setViewportView(WorklistTree);

        jTabbedPane2.addTab("Lista de trabajo", jScrollPane1);

        PatientTree.setRootVisible(false);
        PatientTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ClickPatientTree(evt);
            }
        });
        jScrollPane5.setViewportView(PatientTree);

        jTabbedPane2.addTab("Estudios antiguos", jScrollPane5);

        PatientSearchLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PatientSearchLabel.setText("Buscador de pacientes");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(PatientListLabel)
                        .addGap(16, 16, 16))
                    .addComponent(PatientSearchInput)
                    .addComponent(PatientSearchLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(RemovePatientButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(PatientListRefreshButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(SendButton, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTabbedPane1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(PatientListLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PatientListRefreshButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane2)
                        .addGap(8, 8, 8)
                        .addComponent(PatientSearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PatientSearchInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(RemovePatientButton)
                        .addGap(12, 12, 12))
                    .addComponent(jTabbedPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SendButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        getAccessibleContext().setAccessibleDescription("Main");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void SurnameInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SurnameInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SurnameInputActionPerformed

    private void SexF_RadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SexF_RadioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SexF_RadioActionPerformed

    private void HCEInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HCEInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_HCEInputActionPerformed

    private void SendButtonClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SendButtonClick

        try {
            // TODO add your handling code here:
            Send.setLocationRelativeTo(jTabbedPane1);
            Send.setVisible(true);
            int i = 0;
            /*// Put server names on combobox.
            selectedServerComboBox.removeAllItems();

            ArrayList<Server> serverList = this.controller.getServerNames(); // Gets all servers AET in it's corresponding combobox.
            //ArrayList<Server> serverList = FC.getServerNames();       // Gets all servers AET in it's corresponding combobox.

            for(int j=0;j<serverList.size();j++){
                selectedServerComboBox.addItem(serverList.get(j));
            }*/

            // Inicializes help text.
            dcmSndBuffer.setText(null); 
            // Initialize table rows
            tableModel = (DefaultTableModel) dcmsndTable.getModel();                            
            String query = "patient,consultation,study,acquisition,device WHERE patient.Id=consultation.patient_Id AND study.Id=consultation.Study_Id AND acquisition.Study_Id=consultation.Study_Id AND device.Id=consultation.Device_Id AND Sent=0";
            int max = DB.GetMax(query);
            tableModel.setNumRows(max);
            System.out.println("Row number in table: "+max);
            // Gets data from MySQL to fill the table.
            rs = DB.SQLquery("SELECT AcquisitionName,PatientsName,PatientsSurName,StudyDate,AcquisitionTime,Sent,AETitle FROM "+query);
            rs.beforeFirst();

            while (rs.next()) {
                // Takes values from each row in database.
                String AcquisitionName = rs.getString("AcquisitionName");
                String PatientsName = rs.getString("PatientsName");
                String PatientsSurName = rs.getString("PatientsSurName");
                String PatientsFullName = PatientsName + " " + PatientsSurName;
                String StudyDate = rs.getString("StudyDate");
                String AcquisitionTime = rs.getString("AcquisitionTime");
                int Sent = rs.getInt("Sent");
                //System.out.println("AcquisitionName: " + AcquisitionName + "\n PatientsFullName: " + PatientsFullName + "\n StudyDate: " + StudyDate + "\n AcquisitionTime: " + AcquisitionTime + "\n Sent: " + Sent);

                // Starts drawing the table contents.                
                dcmsndTable.setValueAt(AcquisitionName, i, dcmsndTable.getColumnModel().getColumnIndex("Nombre adquisición"));
                dcmsndTable.setValueAt(PatientsFullName, i, dcmsndTable.getColumnModel().getColumnIndex("Nombre del paciente"));
                dcmsndTable.setValueAt(StudyDate, i, dcmsndTable.getColumnModel().getColumnIndex("Fecha del estudio"));
                dcmsndTable.setValueAt(AcquisitionTime, i, dcmsndTable.getColumnModel().getColumnIndex("Tiempo adquisición"));
                if(Sent == 1){
                    dcmsndTable.setValueAt("Sí", i, dcmsndTable.getColumnModel().getColumnIndex("Enviado"));
                }else{
                    dcmsndTable.setValueAt("No", i, dcmsndTable.getColumnModel().getColumnIndex("Enviado"));
                }
                dcmsndTable.setValueAt(0, i, dcmsndTable.getColumnModel().getColumnIndex("Tiempo enviando (ms)"));
                i++;
            }
            /*Date today = new Date();
            TreePath path = WorklistTree.getAnchorSelectionPath();
            MutableTreeNode node = (MutableTreeNode)path.getLastPathComponent();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
            //model.insertNodeInto(new DefaultMutableTreeNode(formatter.format(today)+"-"+OjoButtonGroup.getSelection().toString()), (MutableTreeNode)node, node.getChildCount());
            model.insertNodeInto(new DefaultMutableTreeNode(formatter.format(today)+" - "), (MutableTreeNode)node, node.getChildCount());
             */
            /*} catch (SQLException ex) {
            Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
            }*/
            /*Date today = new Date();
            TreePath path = WorklistTree.getAnchorSelectionPath();
            MutableTreeNode node = (MutableTreeNode)path.getLastPathComponent();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
            //model.insertNodeInto(new DefaultMutableTreeNode(formatter.format(today)+"-"+OjoButtonGroup.getSelection().toString()), (MutableTreeNode)node, node.getChildCount());
            model.insertNodeInto(new DefaultMutableTreeNode(formatter.format(today)+" - "), (MutableTreeNode)node, node.getChildCount());
             */

        } catch (Exception ex) {
            Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_SendButtonClick
/*
    private void CreatePatient(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreatePatient
        // TODO add your handling code here:
        // Adds a new branch to the JTree.
        int startRow = 0;
        String prefix = newPatient;    // Selects node by name.
        TreePath path = WorklistTree.getNextMatch(prefix, startRow, Position.Bias.Forward);

        int x=0;
        if(path != null){
        String patientName = path.toString();
        //String[] patientNbr = patientName.split(newPatient);
        //String patientNbr = patientName.trim();
        //patientName = patientName.substring(patientName.length()-2,patientName.length()-1);
        System.out.println(patientName);

        //int x = Integer.parseInt(patientName);
        //System.out.println(x);

        }

        model.insertNodeInto(new DefaultMutableTreeNode(prefix+" " +x), topWorklist, topWorklist.getChildCount());
        //modelPatient.insertNodeInto(new DefaultMutableTreeNode(prefix+" " + x), topPatient, topPatient.getChildCount());
        x=x+1;

    }//GEN-LAST:event_CreatePatient
 */
    private void ImagePathInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ImagePathInputActionPerformed
        // TODO add your handling code here:                

    }//GEN-LAST:event_ImagePathInputActionPerformed

    private void PatientListRefreshClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientListRefreshClick
        //controller.updateWorklist(this);
        Worklist.setLocationRelativeTo(jTabbedPane1);
        Worklist.setVisible(true);
    }//GEN-LAST:event_PatientListRefreshClick

    private void UpdateListButtonClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UpdateListButtonClick
        // Hide the window when the download has finished.
        HCERegisterDialog.setVisible(false);        
    }//GEN-LAST:event_UpdateListButtonClick

    private void RemovePatientButtonCreatePatient(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RemovePatientButtonCreatePatient
        TreePath path = null;
        // Find node to remove
        if(WorklistTree.getAnchorSelectionPath() != null){
            path = WorklistTree.getLeadSelectionPath();
        }else if(PatientTree.getAnchorSelectionPath() != null){
            path = PatientTree.getLeadSelectionPath();
        }
        
        if(path == null || path.getPathCount() == 1){
            System.out.println("Jtree not selected");
        }else if(!path.getPathComponent(1).equals(newPatient) || !path.getPathComponent(1).equals(newStudy) || !path.getPathComponent(1).equals(newAcquisition) ){
            //System.out.println("JTree path: "+pathSelected.getPathComponent(1).toString());
            
            String nodeName = path.getPathComponent(1).toString();
            int decision = JOptionPane.showConfirmDialog(this, "Esta seguro/a de eliminar el nodo "+nodeName+"? \nNo podrá recuperar sus estudios.","ALERTA: Eliminar paciente",2,2);
            //System.out.println("Decision: "+decision);
            try{
                if(decision == 0){
                    //DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
                    this.getTreeData(path,false);
                    Integer nodeId;
                    int nodeLevel;

                    if(this.selectedAcquisitionId != null){
                        nodeId = this.selectedAcquisitionId;
                        nodeLevel = 3;
                    }else if(this.selectedStudyId != null){
                        nodeId = this.selectedStudyId;
                        nodeLevel = 2;
                    }else{
                        nodeId = selectedPatientId;
                        nodeLevel = 1;
                    }
                    controller.removeSelectedNode(nodeId,nodeLevel);
                }
            }catch(SQLException ex){
                String error_txt = Application.splitError(ex.toString());
            JOptionPane.showMessageDialog(DemographicPanel, error_txt, MYSQL_EXCEPTION, 2, null);
            }catch(Exception ex){
                String error_txt = Application.splitError(ex.toString());
            JOptionPane.showMessageDialog(DemographicPanel, error_txt, EXCEPTION, 2, null);
            }
        }
        
        
        

        /*
        if(pathSelected == null || pathSelected.getPathCount() == 1){
            System.out.println("Jtree not selected");
        }else if(!pathSelected.getPathComponent(1).equals(newPatient)){
            //System.out.println("JTree path: "+pathSelected.getPathComponent(1).toString());
            // Remove patient node from both JTrees: Check if node exists on each JTree to delete it.
            int startRow = 0;
            String PatientName = pathSelected.getPathComponent(1).toString();
            int decision = JOptionPane.showConfirmDialog(this, "Esta seguro/a de eliminar el paciente "+PatientName+"? \nNo podrá recuperar sus estudios.","ALERTA: Eliminar paciente",2,2);
            if(decision == 0){
                System.out.println("Decision: "+decision);
                //JOptionPane.s;
                TreePath pathWorklist = WorklistTree.getNextMatch(PatientName, startRow, Position.Bias.Forward);
                    //System.out.println("Path deleted from WorklistTree "+pathWorklist);
                TreePath pathPatient = PatientTree.getNextMatch(PatientName, startRow, Position.Bias.Forward);
                    //System.out.println("Path deleted from PatientTree "+pathPatient);
                MutableTreeNode node = null;
                if(pathWorklist != null){
                    node = (MutableTreeNode)pathWorklist.getLastPathComponent();
                    model.removeNodeFromParent(node);
                    System.out.println("Node deleted from WorklistTree "+node.toString());
                }
                if(pathPatient != null){
                    node = (MutableTreeNode)pathPatient.getLastPathComponent();
                    modelPatient.removeNodeFromParent(node);
                    System.out.println("Node deleted from PatientTree "+node.toString());
                }
                // Delete patient from database:
                //Patient p = (Patient) patientHash.get(new String(node.toString())); // Search by name --> IdPatient Output
                //String IdPatient = p.getId();
                System.out.println("IdPatient obtained from hastable will be deleted from database: " + selectedPatientId);
                //DB.SQLupdate("DELETE FROM patient WHERE Id='"+selectedPatientId+"'",false,0,null);
            }
        }*/
    }//GEN-LAST:event_RemovePatientButtonCreatePatient

    private void SexM_RadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SexM_RadioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SexM_RadioActionPerformed

    private void LeftEyeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LeftEyeRadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_LeftEyeRadioButtonActionPerformed

    private void RightEyeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RightEyeRadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_RightEyeRadioButtonActionPerformed

    private void ImagePathButtonClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ImagePathButtonClick
        // TODO add your handling code here:
        imageDialog.setVisible(false);   // En primer lugar cierra el panel de imagen completa.
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos de imagen", "jpg", "jpeg", "gif", "png", "bmp", "tiff");  // Creates a filter named 'Archivos de imagen' that lets pass files with different image format extensions.
        ImageFileChooser.setFileFilter(filter); // Applies the filter on the FileChooser object.

        int returnVal = ImageFileChooser.showOpenDialog(ImagePreviewLabel);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            /*try {
                File file = ImageFileChooser.getSelectedFile();
                boolean isMoved = FLib.moveFile(file.getName(), file.getPath(), this.savePath);
                System.out.println("isMoved: " + isMoved);
                loadImage(new File(this.savePath + "\\" + file.getName())); // Loads the image from temporary database.   */             
                loadImage(ImageFileChooser.getSelectedFile()); // Loads the image from temporary database.                
            /*}catch (FileLibrary.MyException ex) {   // Errors related to dcm file deletion.
                String error = ex.getMessage();
                JOptionPane.showMessageDialog(this, error);
            }*/

        }else if(returnVal == JFileChooser.ERROR_OPTION){
            ImagePreviewLabel.setIcon(error);                                  // Paints the predefined ImageIcon on a Label.
            ImagePathInput.setText("NO SE HA CARGADO NINGUNA IMAGEN");  // Updates the path value on a text input.
            ImageFileChooser.setSelectedFile(null);
        }
}//GEN-LAST:event_ImagePathButtonClick

    private void FixationLossesInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FixationLossesInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FixationLossesInputActionPerformed

    private void FalsePositivesInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FalsePositivesInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FalsePositivesInputActionPerformed

    private void TestDurationInput2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestDurationInput2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TestDurationInput2ActionPerformed

    private void FovealRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FovealRadioButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FovealRadioButton1ActionPerformed

    private void FovealRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FovealRadioButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FovealRadioButton2ActionPerformed

    private void FalseNegativesInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FalseNegativesInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FalseNegativesInputActionPerformed

    private void TestDurationInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestDurationInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TestDurationInput1ActionPerformed

    private void SensibilityInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SensibilityInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SensibilityInputActionPerformed

    private void ImagePreviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ImagePreviewButtonActionPerformed
        // TODO add your handling code here:
        
        String imagePath = ImagePathInput.getText();
        //System.out.println("Path: "+imagePath);
        if(imagePath != null){            
            ImageIcon iconoCargado = new ImageIcon(imagePath); // Creates an ImageIcon from URL path.
            
            // Resize Icon:
            Image img = iconoCargado.getImage();    // Transform Icon in Image.
                        
            int imgWidth = img.getWidth(UserLabel);
            int imgHeight = img.getHeight(UserLabel);
            int labelWidth = ImageLabel.getWidth();
            int labelHeight = ImageLabel.getHeight();
            
            //super.setApplication.getScreenSize();
            int screenHeight = application.screenSize.height;
            int screenWidth = application.screenSize.width;

            double scaleFactor;
            int ImageMargin = 70;
            if (imgWidth < screenWidth && imgHeight < screenHeight){
                //System.out.println("Imagen MENOR que pantalla");
                scaleFactor = 1;
            }else{
                //System.out.println("Imagen MAYOR que pantalla");
                scaleFactor = scaleImage(imgWidth,imgHeight,screenWidth-ImageMargin,screenHeight-ImageMargin);
            }
            // Multiplies original image by scale factor:
            int width = (int) (imgWidth * scaleFactor);
            int height = (int) (imgHeight * scaleFactor);
            //System.out.println(width+" resta "+height);

            Image newimg = img.getScaledInstance(width, height,  java.awt.Image.SCALE_AREA_AVERAGING);   // Rsize image.
            iconoCargado = new ImageIcon(newimg);   // Rewrite Icon.

            //System.out.println(img.getWidth(UserLabel)+" Inicial "+img.getHeight(UserLabel));
            //System.out.println(newimg.getWidth(UserLabel)+" Final "+newimg.getHeight(UserLabel));
            
            //ImageLabel.setSize(newimg.getWidth(UserLabel), newimg.getHeight(UserLabel));
            imageDialog.setSize(newimg.getWidth(UserLabel)+ImageMargin,newimg.getHeight(UserLabel)+ImageMargin);
            ImageLabel.setIcon(iconoCargado);                  // Paints the ImageIcon on a Label.
            imageDialog.setVisible(true);
        }
         
    }//GEN-LAST:event_ImagePreviewButtonActionPerformed

    private void DMInput2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DMInput2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DMInput2ActionPerformed

    private void DMInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DMInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DMInput1ActionPerformed

    private void DSMInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DSMInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DSMInput1ActionPerformed

    private void DSMInput2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DSMInput2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DSMInput2ActionPerformed

    private void SFInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SFInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SFInput1ActionPerformed

    private void CPSDInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CPSDInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CPSDInput1ActionPerformed

    private void SFCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SFCheckBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SFCheckBoxActionPerformed

    private void CPSDCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CPSDCheckBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CPSDCheckBoxActionPerformed

    private void RefreshButton_WFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefreshButton_WFActionPerformed
        controller.updateWorklist(this);    
    }//GEN-LAST:event_RefreshButton_WFActionPerformed

    private void DilatationRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DilatationRadioButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DilatationRadioButton1ActionPerformed

    private void DilatationRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DilatationRadioButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DilatationRadioButton3ActionPerformed

    private void ClickWorklistTree(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClickWorklistTree
        if(jTabbedPane2.getSelectedIndex() == 0 && WorklistTree.getAnchorSelectionPath() != null){  // WorklistTree tab is selected and there is a node selected in it.
            TreePath path = WorklistTree.getLeadSelectionPath();
            this.getTreeData(path,true);            
        }else{
            System.out.println("Jtree not selected");
        }
    }//GEN-LAST:event_ClickWorklistTree

    private void ClickPatientTree(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClickPatientTree
        if(jTabbedPane2.getSelectedIndex() == 1 && PatientTree.getAnchorSelectionPath() != null){   // PatientTree tab is selected and there is a node selected in it.
            TreePath path = PatientTree.getLeadSelectionPath();
            this.getTreeData(path,true);
        }else{
            System.out.println("Jtree not selected");
        }
    }//GEN-LAST:event_ClickPatientTree

    private void BirthDateInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BirthDateInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_BirthDateInputActionPerformed

    private void StudyDateInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StudyDateInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_StudyDateInputActionPerformed
    // DCMSND Frame buttons:
    private void dcmDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dcmDeleteButtonActionPerformed
        // TODO add your handling code here:
        int selection = JOptionPane.showConfirmDialog(Send, "¿Esta seguro/a de querer eliminar del disco las adquisiciones seleccionadas?");
        if(selection == 0){            
            int[] selected = dcmsndTable.getSelectedRows();
            int AcqCol= dcmsndTable.getColumnModel().getColumnIndex("Nombre adquisición");  // Get the column number where the name of acquisition is writted.

            for(int i=0;i<=selected.length-1;i++){
                String acquisitionName = (String) dcmsndTable.getValueAt(selected[i], AcqCol);  // Get the acquisition name for the row selected.
                try{
                    // Delete rows in MySQL                    
                    DB.SQLupdate("DELETE FROM acquisition WHERE AcquisitionName='"+acquisitionName+"'", false, 0, null);
                    
                    // Removes each row according to before deleted ones.
                    tableModel.removeRow(selected[i] - i); // Removes each row according to before deleted ones.

                    // Removes each file from imgs2send folder (if exists).
                    ArrayList FolderpathList = FLib.getFilesOnFolder(this.inPath,".dcm|.DCM"); // Gets dicom file paths from a selected folder.
                    String File2Delete = FLib.isInFolder(this.inPath,acquisitionName,FolderpathList);
                    System.out.println("File2Delete: "+File2Delete);
                    FLib.deleteFile(File2Delete);    // Delete the file if exists.

                }catch (SQLException ex) {  // Errors related to MySQL acquisition delete.
                    JOptionPane.showMessageDialog(Send, "Ha fallado el borrado de la adquisición '"+acquisitionName+"':\nError al conectar con la base de datos MySQL");
                    dcmsndTable.setValueAt("Error al conectar con MySQL", selected[i], dcmsndTable.getColumnModel().getColumnIndex("Mensaje"));
                    dcmSndBuffer.append("Error al conectar con MySQL durante el borrado\n");
                    Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
                }catch (FileLibrary.MyException ex) {
                    String error = ex.getMessage();
                    dcmSndBuffer.append("ADVERTENCIA:\n "+error+"\n");
                }
                
            }
        }
}//GEN-LAST:event_dcmDeleteButtonActionPerformed

    private void dcmSndButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dcmSndButtonActionPerformed
        // TODO add your handling code here:
        int[] selected = dcmsndTable.getSelectedRows();
        int AcqCol= dcmsndTable.getColumnModel().getColumnIndex("Nombre adquisición");  // Get the column number where the name of acquisition is writted.

        dcmSND SND = null;
        //ArrayList acquisition = new ArrayList();
        JFrameBase.SendingProgressBar.setMinimum(0);
        JFrameBase.SendingProgressBar.setMaximum(selected.length-1);
        JFrameBase.SendingProgressBar.setValue(0);        

        //this.SendingProgressBar.setStringPainted(true);
        //SND.getFilesOnFolder();
                
        boolean isError = false;
        int sentNbr = 0;
        for (int i=0;i<=selected.length-1;i++){
            String isSent= dcmsndTable.getValueAt(selected[i], dcmsndTable.getColumnModel().getColumnIndex("Enviado")).toString();  // The current acquisition is already sent.
            if(isSent.equals("No")){    // Ignores previously sent acquisitions.
                dcmsndTable.setValueAt("Envío en progreso...", selected[i], dcmsndTable.getColumnModel().getColumnIndex("Mensaje"));    // Sending process starts.
                long t_start = new Date().getTime();    // Time in miliseconds when the operation starts.
                //System.out.println("Col: "+AcqCol+" Row:"+selected[i]);
                String acquisitionName = (String) dcmsndTable.getValueAt(selected[i],AcqCol);   // Get the acquisition name from the selected row.
                //acquisition.add(i,acquisitionName);
                //System.out.println("acquisition[i]:"+acquisition.get(i));
                try {
                    // Start DICOM send process.
                    SND = new dcmSND(this,acquisitionName);
                    System.out.println("SND: "+SND);
                    String cmd = SND.getCMD();
                    dcmSndBuffer.append("System Call: ["+cmd+"]\n");
                    String Buffer = SND.getBuffer();
                    dcmSndBuffer.append("Buffer result: \n"+Buffer+"\n");

                    // Refreshes Send variable on table from database.
                    rs = DB.SQLquery("SELECT Sent FROM acquisition WHERE AcquisitionName='"+acquisitionName+"'");
                    rs.first();
                    int Sent = rs.getInt("Sent");
                    //System.out.println("******** acquisitionName: "+acquisitionName+" selected[i]: "+selected[i]+" Sent: "+Sent);
                    if(Sent == 1){
                        dcmsndTable.setValueAt("Sí", selected[i], dcmsndTable.getColumnModel().getColumnIndex("Enviado"));
                    }else{
                        dcmsndTable.setValueAt("No", selected[i], dcmsndTable.getColumnModel().getColumnIndex("Enviado"));
                    }

                    // Writting correct sent messages on table.
                    dcmsndTable.setValueAt(null, selected[i], dcmsndTable.getColumnModel().getColumnIndex("Mensaje"));    // Sending process ends correctly.
                    long t_end = new Date().getTime();
                    dcmsndTable.setValueAt(t_end-t_start, selected[i], dcmsndTable.getColumnModel().getColumnIndex("Tiempo enviando (ms)"));

                    // Changes on progress bar.
                    sentNbr++;
                    SendingLabel.setText("Enviadas "+sentNbr+" imágenes de "+selected.length);  // Text next to the progress bar.
                    JFrameBase.SendingProgressBar.setMaximum(selected.length);
                    JFrameBase.SendingProgressBar.setValue(sentNbr);
                    //JFrameBase.SendingProgressBar.setStringPainted(true);
                    Rectangle progressRect = JFrameBase.SendingProgressBar.getBounds();
                    progressRect.x = 0;
                    progressRect.y = 0;
                    JFrameBase.SendingProgressBar.paintImmediately(progressRect);
                    
                } catch (FileLibrary.MyException ex) {
                    String error = ex.getMessage();
                    dcmsndTable.setValueAt("Error: "+error, selected[i], dcmsndTable.getColumnModel().getColumnIndex("Mensaje"));
                    dcmSndBuffer.append("Error:\n "+error+"\n");
                    isError = true;
                    //JOptionPane.showMessageDialog(Send, "Ha fallado el envío al PACS de la adquisición '"+acquisitionName+"':\n"+error, "Error!",JOptionPane.ERROR_MESSAGE);
                    Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
                } catch (dcmSND.MyException ex) {
                    String error = ex.getMessage();
                    dcmsndTable.setValueAt("Error: "+error, selected[i], dcmsndTable.getColumnModel().getColumnIndex("Mensaje"));
                    dcmSndBuffer.append("Error:\n "+error+"\n");
                    isError = true;
                    //JOptionPane.showMessageDialog(Send, "Ha fallado el envío al PACS de la adquisición '"+acquisitionName+"':\n"+error, "Error!",JOptionPane.ERROR_MESSAGE);
                    Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);                   
                } catch (SQLException ex) {
                    String error = SND.getError();
                    dcmsndTable.setValueAt("Error al conectar con MySQL", selected[i], dcmsndTable.getColumnModel().getColumnIndex("Mensaje"));
                    dcmSndBuffer.append("Error al conectar con MySQL:\n"+error+"\n");
                    isError = true;
                    //JOptionPane.showMessageDialog(Send, "Ha fallado el envío al PACS de la adquisición '"+acquisitionName+"':\nError al conectar con la base de datos MySQL");
                    Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
                    //throw ex;
                }
            }
        }
          
        // Shows an alert window when finish sending process.
        if(isError == true){
            JOptionPane.showMessageDialog(Send, "Ha fallado el envío al PACS de alguna/s adquisición/es", "Error!",JOptionPane.ERROR_MESSAGE);
        }else{
            JOptionPane.showMessageDialog(Send, "Las adquisiciones han sido correctamente enviadas al PACS");            
            dcmsndTable.clearSelection();   // Clear selection after sending the acquisitions.
        }
        
    }//GEN-LAST:event_dcmSndButtonActionPerformed

    private void SelectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectAllButtonActionPerformed
        // TODO add your handling code here:
        if(SelectAllButton.isSelected() == true){   // Select all.
            dcmsndTable.selectAll();
            dcmsndTable.getRowCount();
            for(int i=0;i<=dcmsndTable.getRowCount()-1;i++){                
                String isSent= dcmsndTable.getValueAt(i, dcmsndTable.getColumnModel().getColumnIndex("Enviado")).toString();                
                if(isSent.equals("Sí")){
                    System.out.println("Deselect row nbr: "+i);
                    dcmsndTable.setRowSelectionAllowed(true);
                    //dcmsndTable.changeSelection(i,0,false,false);
                    dcmsndTable.changeSelection(i,dcmsndTable.getColumnCount()-1,true,false);
                }
            }
            
        }else{  // Deselect all.
            dcmsndTable.clearSelection();
        }
    }//GEN-LAST:event_SelectAllButtonActionPerformed

    private void RxLeftEyeInput3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RxLeftEyeInput3ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RxLeftEyeInput3ActionPerformed

    private void RxLeftEyeInput2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RxLeftEyeInput2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RxLeftEyeInput2ActionPerformed

    private void RxLeftEyeInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RxLeftEyeInput1ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RxLeftEyeInput1ActionPerformed

    private void RxRightEyeInput3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RxRightEyeInput3ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RxRightEyeInput3ActionPerformed

    private void RxRightEyeInput2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RxRightEyeInput2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RxRightEyeInput2ActionPerformed

    private void RxRightEyeInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RxRightEyeInput1ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RxRightEyeInput1ActionPerformed

    private void BackgroundLuminanceComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackgroundLuminanceComboBox2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_BackgroundLuminanceComboBox2ActionPerformed

    private void PatientSaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientSaveButtonActionPerformed
        int response = JOptionPane.showConfirmDialog(DemographicPanel, addPatientQuestion, infoTxt,JOptionPane.INFORMATION_MESSAGE);
        if(response == 0){  // Clicked over 'YES'
            this.controller.addNewPatient(this);
        }else{System.out.println("Cancelada la acción de Guardar PACIENTE");}
    }//GEN-LAST:event_PatientSaveButtonActionPerformed

    private void HCEInputFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_HCEInputFocusLost
        String HCE = HCEInput.getText();
        controller.checkPatientHCE(HCE);
    }//GEN-LAST:event_HCEInputFocusLost

    private void StudySaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StudySaveButtonActionPerformed
        int response = JOptionPane.showConfirmDialog(DemographicPanel, addStudyQuestion, infoTxt,JOptionPane.INFORMATION_MESSAGE);
        if(response == 0){  // Clicked over 'YES'
            this.controller.addNewStudy(this);
        }else{System.out.println("Cancelada la acción de Guardar ESTUDIO");}
    }//GEN-LAST:event_StudySaveButtonActionPerformed

    private void AcquisitionSaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AcquisitionSaveButtonActionPerformed
        
        int response = JOptionPane.showConfirmDialog(DemographicPanel, addAcquisitionQuestion, infoTxt,JOptionPane.INFORMATION_MESSAGE);
        if(response == 0){  // Clicked over 'YES'
            controller.addNewAcquisition(this);
        }else{System.out.println("Cancelada la acción de Guardar ADQUISICIÓN");}
    }//GEN-LAST:event_AcquisitionSaveButtonActionPerformed

    private void KeyReleasedFilter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_KeyReleasedFilter
        String patientFilter = PatientSearchInput.getText();   // Selects node by name.

        // Initialize Treemodels:
        topPatient.removeAllChildren();
        topWorklist.removeAllChildren();
        // Put new data in Treemodels:
        List<String> patientsFullName = Arrays.asList("PatientsName","PatientsSurName");
        controller.loadPatientList(patientsFullName, patientFilter);
        // Repaints Treemodels:
        this.modelPatient.reload();
        this.model.reload();
    }//GEN-LAST:event_KeyReleasedFilter

    private void FixationLossesCheckedInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FixationLossesCheckedInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FixationLossesCheckedInputActionPerformed

    private void newReferralNoteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newReferralNoteButtonActionPerformed
        ReferralNote.setVisible(false);
    }//GEN-LAST:event_newReferralNoteButtonActionPerformed

    private void PatientIdTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientIdTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PatientIdTextFieldActionPerformed

    private void PatientNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientNameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PatientNameTextFieldActionPerformed

    private void PatientSurNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientSurNameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PatientSurNameTextFieldActionPerformed

    private void PatientBirthDateTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientBirthDateTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PatientBirthDateTextFieldActionPerformed

    private void RequestingPhysicianTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RequestingPhysicianTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_RequestingPhysicianTextFieldActionPerformed

    private void RequestedProcedureDescriptionTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RequestedProcedureDescriptionTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_RequestedProcedureDescriptionTextFieldActionPerformed

    private void ScheduledProcedureStepDescriptionTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ScheduledProcedureStepDescriptionTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ScheduledProcedureStepDescriptionTextFieldActionPerformed

    private void ScheduledProcedureStartDateTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ScheduledProcedureStartDateTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ScheduledProcedureStartDateTextFieldActionPerformed

    private void ScheduledProcedureStartTimeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ScheduledProcedureStartTimeTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ScheduledProcedureStartTimeTextFieldActionPerformed

    private void TestPatternTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestPatternTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TestPatternTextFieldActionPerformed

    private void TestStrategyTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestStrategyTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TestStrategyTextFieldActionPerformed

    private void TestModeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestModeTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TestModeTextFieldActionPerformed

    private void newReferralNoteButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newReferralNoteButton1ActionPerformed
        controller.ReferralNote2database(this);        
    }//GEN-LAST:event_newReferralNoteButton1ActionPerformed

    private void PatientSexFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PatientSexFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PatientSexFieldActionPerformed

    private void ClickWorklistXTable(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClickWorklistXTable
        controller.readReferralNote(this);
    }//GEN-LAST:event_ClickWorklistXTable
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JTextField AccessNumberInput_WF;
    private javax.swing.JLabel AccessNumberLabel_WF;
    public javax.swing.JTextField AcquisitionNameInput;
    private javax.swing.JButton AcquisitionSaveButton;
    public javax.swing.JComboBox BackgroundLuminanceComboBox1;
    public javax.swing.JComboBox BackgroundLuminanceComboBox2;
    private javax.swing.JLabel BackgroundLuminanceLabel1;
    private javax.swing.JLabel BackgroundLuminanceLabel2;
    private javax.swing.JLabel BackgroundLuminanceLabel3;
    private javax.swing.JLayeredPane BackgroundLuminanceLayeredPane;
    public static org.jdesktop.swingx.JXDatePicker BirthDateInput;
    private javax.swing.JLabel BirthDateLabel;
    private javax.swing.JLayeredPane ButtonsLayeredPane;
    public javax.swing.JCheckBox CPSDCheckBox;
    public javax.swing.JTextField CPSDInput1;
    private javax.swing.JLabel CPSDLabel1;
    private javax.swing.JLayeredPane ClinicDataLayeredPane;
    public javax.swing.JPanel ClinicPanel;
    private javax.swing.JLabel DEPCLabel2;
    private javax.swing.JLabel DEPLabel3;
    private javax.swing.JLabel DEPLabel4;
    public javax.swing.JCheckBox DMCheckBox;
    public javax.swing.JTextField DMInput1;
    public javax.swing.JTextField DMInput2;
    private javax.swing.JLabel DMLabel1;
    private javax.swing.JLabel DMLabel2;
    private javax.swing.JLabel DMLabel3;
    public javax.swing.JCheckBox DSMCheckBox;
    public javax.swing.JTextField DSMInput1;
    public javax.swing.JTextField DSMInput2;
    private javax.swing.JLabel DSMLabel1;
    public javax.swing.JPanel DemographicPanel;
    private javax.swing.JRadioButton DilatationRadioButton1;
    private javax.swing.JRadioButton DilatationRadioButton3;
    private static javax.swing.JDialog ErrorDialog;
    private static javax.swing.JTextPane ErrorPane;
    public javax.swing.ButtonGroup EyeButtonGroup;
    private javax.swing.JLayeredPane EyeDilatationLayeredPane1;
    private javax.swing.JLabel EyeLabel1;
    private javax.swing.JLayeredPane EyeLayeredPane;
    private javax.swing.JLabel FCPLabel2;
    public javax.swing.JTextField FalseNegativesInput;
    private javax.swing.JLabel FalseNegativesLabel1;
    private javax.swing.JLabel FalseNegativesLabel2;
    public javax.swing.JTextField FalsePositivesInput;
    private javax.swing.JLabel FalsePositivesLabel1;
    private javax.swing.JLabel FalsePositivesLabel2;
    public javax.swing.JTextField FixationLossesCheckedInput;
    public javax.swing.JTextField FixationLossesInput;
    private javax.swing.JLabel FixationLossesLabel;
    private javax.swing.JLabel FixationLossesLabel1;
    public javax.swing.JComboBox FixationStrategyComboBox;
    private javax.swing.JLabel FixationStrategyLabel;
    public javax.swing.JComboBox FixationTargetComboBox;
    private javax.swing.JLabel FixationTargetLabel;
    public javax.swing.ButtonGroup FovealButtonGroup;
    private javax.swing.JLabel FovealLabel;
    private javax.swing.JLayeredPane FovealLayeredPane;
    public javax.swing.JRadioButton FovealRadioButton1;
    public javax.swing.JRadioButton FovealRadioButton2;
    public javax.swing.JComboBox GlobalIndexNameComboBox;
    private javax.swing.JLabel GlobalIndexNameLabel;
    private javax.swing.JLayeredPane GlobalIndicesPane;
    private javax.swing.JButton GoButton;
    public javax.swing.JFormattedTextField HCEInput;
    private javax.swing.JLabel HCELabel;
    private javax.swing.JDialog HCERegisterDialog;
    public javax.swing.JLabel HCE_checkLabel;
    private javax.swing.JLabel ImageLabel;
    public javax.swing.JPanel ImagePanel;
    private javax.swing.JButton ImagePathButton;
    public javax.swing.JTextField ImagePathInput;
    private javax.swing.JLayeredPane ImagePathLayeredPane;
    private javax.swing.JButton ImagePreviewButton;
    public javax.swing.JLabel ImagePreviewLabel;
    public javax.swing.JRadioButton LeftEyeRadioButton;
    public javax.swing.JTextField NameInput;
    private javax.swing.JLabel NameLabel;
    public javax.swing.JComboBox PHGComboBox;
    private javax.swing.JLabel PHGLabel;
    private javax.swing.JPasswordField PasswordInput;
    private javax.swing.JLabel PasswordLabel;
    private javax.swing.JLabel PatientBirthDateLabel;
    public javax.swing.JTextField PatientBirthDateTextField;
    private javax.swing.JLabel PatientCommentsLabel;
    public javax.swing.JTextArea PatientCommentsTextArea;
    public javax.swing.JTextField PatientIdInput_WF;
    private javax.swing.JLabel PatientIdLabel;
    private javax.swing.JLabel PatientIdLabel_WF;
    public javax.swing.JTextField PatientIdTextField;
    private javax.swing.JLabel PatientLabel;
    private javax.swing.JLabel PatientListLabel;
    private javax.swing.JButton PatientListRefreshButton;
    public javax.swing.JTextField PatientNameInput_WF;
    private javax.swing.JLabel PatientNameLabel;
    private javax.swing.JLabel PatientNameLabel_WF;
    public javax.swing.JTextField PatientNameTextField;
    private javax.swing.JButton PatientSaveButton;
    public javax.swing.JTextField PatientSearchInput;
    private javax.swing.JLabel PatientSearchLabel;
    public javax.swing.JTextField PatientSexField;
    private javax.swing.JLabel PatientSexLabel;
    private javax.swing.JLabel PatientSurNameLabel;
    public javax.swing.JTextField PatientSurNameTextField;
    public javax.swing.JTree PatientTree;
    private javax.swing.JLabel PerformingPhysicianLabel;
    public javax.swing.JComboBox PerformingPhysicianNameComboBox;
    public javax.swing.JComboBox PerformingPhysicianNameComboBox1;
    private javax.swing.JLabel PhysicianLabel;
    private javax.swing.JLabel Procedure;
    private javax.swing.JProgressBar ProgressBar;
    private javax.swing.JScrollPane ProgressScrollPane;
    private javax.swing.JTextPane ProgressTextPane;
    private javax.swing.JLayeredPane ReferralDataLayeredPane;
    public javax.swing.JFrame ReferralNote;
    private javax.swing.JButton RefreshButton_WF;
    private javax.swing.JLayeredPane ReliabilityLayeredPane;
    private javax.swing.JButton RemovePatientButton;
    private javax.swing.JLabel RequestedProcedureDescriptionLabel;
    public javax.swing.JTextField RequestedProcedureDescriptionTextField;
    private javax.swing.JLabel RequestingPhysicianLabel;
    public javax.swing.JTextField RequestingPhysicianTextField;
    public javax.swing.JRadioButton RightEyeRadioButton;
    private javax.swing.JLabel RxLabel1;
    public javax.swing.JTextField RxLeftEyeInput1;
    public javax.swing.JTextField RxLeftEyeInput2;
    public javax.swing.JTextField RxLeftEyeInput3;
    private javax.swing.JLabel RxLeftEyeLabel;
    private javax.swing.JLabel RxLeftEyeLabel1;
    private javax.swing.JLabel RxLeftEyeLabel2;
    private javax.swing.JLabel RxLeftEyeLabel3;
    private javax.swing.JLayeredPane RxPane1;
    public javax.swing.JTextField RxRightEyeInput1;
    public javax.swing.JTextField RxRightEyeInput2;
    public javax.swing.JTextField RxRightEyeInput3;
    private javax.swing.JLabel RxRightEyeLabel;
    private javax.swing.JLabel RxRightEyeLabel1;
    private javax.swing.JLabel RxRightEyeLabel2;
    public javax.swing.JCheckBox SFCheckBox;
    public javax.swing.JTextField SFInput1;
    private javax.swing.JLabel SFPLabel1;
    private javax.swing.JLabel ScheduledProcedureStartDateLabel;
    public javax.swing.JTextField ScheduledProcedureStartDateTextField;
    private javax.swing.JLabel ScheduledProcedureStartTimeLabel;
    public javax.swing.JTextField ScheduledProcedureStartTimeTextField;
    private javax.swing.JLabel ScheduledProcedureStepDescriptionLabel;
    public javax.swing.JTextField ScheduledProcedureStepDescriptionTextField;
    private javax.swing.JToggleButton SelectAllButton;
    private javax.swing.JLabel SelectedServerLabel;
    public javax.swing.JFrame Send;
    private javax.swing.JButton SendButton;
    private javax.swing.JLabel SendingLabel;
    public static javax.swing.JProgressBar SendingProgressBar;
    public javax.swing.JTextField SensibilityInput;
    private javax.swing.JLabel SensibilityLabel1;
    private javax.swing.JLabel SensibilityLabel2;
    public javax.swing.ButtonGroup SexButtonGroup;
    public javax.swing.JRadioButton SexF_Radio;
    private javax.swing.JLabel SexLabel;
    public javax.swing.JRadioButton SexM_Radio;
    public javax.swing.JComboBox StimulusComboBox1;
    public javax.swing.JComboBox StimulusComboBox2;
    private javax.swing.JLabel StimulusLabel;
    private javax.swing.JLabel StimulusLabel2;
    private javax.swing.JLabel StimulusLabel3;
    private javax.swing.JLayeredPane StimulusLayeredPane;
    public javax.swing.JTextArea StudyCommentsTextArea;
    public static org.jdesktop.swingx.JXDatePicker StudyDateInput;
    private javax.swing.JLabel StudyDateLabel;
    public javax.swing.JTextField StudyDescriptionInput_WF;
    private javax.swing.JLabel StudyDescriptionLabel;
    private javax.swing.JLabel StudyDescriptionLabel_WF;
    public javax.swing.JTextArea StudyDescriptionTextArea;
    public javax.swing.JTextField StudyNameInput;
    private javax.swing.JLabel StudyNameLabel;
    private javax.swing.JLabel StudyNameLabel1;
    private javax.swing.JButton StudySaveButton;
    public javax.swing.JTextField SurnameInput;
    private javax.swing.JLabel SurnameLabel;
    public javax.swing.JTextField TestDurationInput1;
    public javax.swing.JTextField TestDurationInput2;
    private javax.swing.JLabel TestDurationLabel1;
    private javax.swing.JLabel TestDurationLabel2;
    private javax.swing.JLabel TestDurationLabel3;
    private javax.swing.JLabel TestModeLabel;
    public javax.swing.JTextField TestModeTextField;
    public javax.swing.JComboBox TestModesComboBox;
    private javax.swing.JLabel TestModesLabel;
    private javax.swing.JLabel TestPatternLabel;
    public javax.swing.JTextField TestPatternTextField;
    public javax.swing.JComboBox TestPatternsComboBox;
    private javax.swing.JLabel TestPatternsLabel;
    public javax.swing.JComboBox TestStrategyComboBox;
    private javax.swing.JLabel TestStrategyLabel;
    private javax.swing.JLabel TestStrategyLabel1;
    public javax.swing.JTextField TestStrategyTextField;
    private javax.swing.JTextField UserInput;
    private javax.swing.JLabel UserLabel;
    public javax.swing.JFrame Worklist;
    private javax.swing.ButtonGroup WorklistDateButtonGroup;
    private javax.swing.JLabel WorklistDateLabel_WF;
    public javax.swing.JRadioButton WorklistDate_Radio1;
    public javax.swing.JRadioButton WorklistDate_Radio2;
    public javax.swing.JRadioButton WorklistDate_Radio3;
    private javax.swing.JLabel WorklistDate_WF;
    private javax.swing.JLayeredPane WorklistLayeredPane;
    public javax.swing.JTree WorklistTree;
    public org.jdesktop.swingx.JXTable WorklistXTable;
    private javax.swing.JButton dcmDeleteButton;
    private javax.swing.JTextArea dcmSndBuffer;
    private javax.swing.JButton dcmSndButton;
    public javax.swing.JTable dcmsndTable;
    private javax.swing.JDialog imageDialog;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JLayeredPane jLayeredPane4;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    public javax.swing.JTabbedPane jTabbedPane1;
    public javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JButton newReferralNoteButton;
    private javax.swing.JButton newReferralNoteButton1;
    private javax.swing.JLayeredPane patientLayeredPane;
    public javax.swing.JComboBox selectedServerComboBox;
    public javax.swing.JComboBox selectedServerComboBox1;
    private javax.swing.JLabel studyCommentsLabel;
    // End of variables declaration//GEN-END:variables

    /*public void setScreenSize(){
            // Adjust Main frame's size
            screenSize = super.getToolkit().getScreenSize();
            int screenWidth = screenSize.width;
            int screenHeight = screenSize.height-30;
            super.setSize(screenWidth, screenHeight);
            Send.setSize(screenWidth, screenHeight/2);
            model = (DefaultTreeModel)WorklistTree.getModel();
            modelPatient = (DefaultTreeModel)PatientTree.getModel();
    }*/
    
    public static double scaleImage(int oldWidth, int oldHeight, int newWidth, int newHeight){
        //System.out.println("******* START of scaleImage ******* ");
        // Get's multiplier:
        double scaleFactor = 0;
        double difAnchura = (double)oldWidth / (double)newWidth;
        double difAltura = (double)oldHeight / (double)newHeight;
        // Analize image proportions:
        if (oldHeight > oldWidth)
        {
            if (difAltura > difAnchura){
                scaleFactor = (double)newHeight / (double)oldHeight;
            }else{
                scaleFactor = (double)newWidth / (double)oldWidth;
            }
        }
        else{
            if (difAltura > difAnchura){
                scaleFactor = (double)newHeight / (double)oldHeight;
            }else{
                scaleFactor = (double)newWidth / (double)oldWidth;
            }
        }
        // Returns new scale:
        return scaleFactor;
    }
    
    /*public void updatePhysician(){
        try {
            System.out.println("******* updatePhysician ******* ");
            PerformingPhysicianComboBox.removeAllItems();   // Delete all old components to restart writing.
            int max=0;
            max = DB.GetMax("physician");    // Gets table row number.
            System.out.println("Numero de physicians: "+max);
            // ! Pueden aparecer physicians repetidos porque no coinciden los espacios en physicians worklist.
            // ! Don't forget that this query is relationed with stateChangedPhysicianSelect's one.
            rs = DB.SQLquery("SELECT * FROM physician ORDER BY PerformingPhysiciansName,PerformingPhysiciansSurName");
                     
            PerformingPhysiciansName.clear();
            PerformingPhysiciansSurName.clear();
            PhysicianId.clear();
            for (int j=0;j<=max-1;j++){
                // Draws the physicians name list on the selector.
                rs.absolute(j+1);                
                PerformingPhysiciansName.add(j,rs.getString("PerformingPhysiciansName"));
                PerformingPhysiciansSurName.add(j,rs.getString("PerformingPhysiciansSurName"));
                PhysicianId.add(j,rs.getString("PhysicianId"));                
                System.out.println(PerformingPhysiciansName.elementAt(j)+" "+PerformingPhysiciansSurName.elementAt(j));
                
                // Writes the physicians full name on the jComboBox.
                PerformingPhysicianComboBox.insertItemAt(PerformingPhysiciansName.elementAt(j)+" "+PerformingPhysiciansSurName.elementAt(j),j);
                //PerformingPhysicianComboBox.insertItemAt(rs.getString("PerformingPhysiciansName")+" "+rs.getString("PerformingPhysiciansSurName"),j);
                System.out.println(rs.getString("PerformingPhysiciansName")+" "+rs.getString("PerformingPhysiciansSurName")"));
            }

        } catch (SQLException ex) {
            Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
        }    
    }*/
        
    public void getTreeData(TreePath path, boolean changeData){
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
        this.x = null;
        this.y = null;
        this.z = null;
        
        try{
            jTabbedPane1.setEnabledAt(1,true);          // Shows study tab.
            jTabbedPane1.setEnabledAt(2,true);    // Shows acquisition tab.

            int nodeLevel = selectedNode.getLevel();
            //System.out.println("Node level: "+selectedNode.getLevel());
            if(nodeLevel == 1){    // Patient selected.
                this.x = (view.Patient)selectedNode.getUserObject();
                Integer patientId = x.getPatientId();
                System.out.println("patientsFullName: "+x.toString()+" => patientId: "+patientId);
                if(changeData == true){
                    this.jTabbedPane1.setSelectedIndex(0);
                    if(patientId != null){this.controller.changeSelectedPatient(patientId); // Case of load an existing patient.
                    }else{this.controller.changeSelectedPatient(null);}                     // Case of new patient.
                    this.controller.changeSelectedStudy(null);                              // Selecting by patient the study becomes allways empty.
                }
                this.selectedPatientId = patientId;
                this.selectedStudyId = null;
                this.selectedAcquisitionId = null;
                jTabbedPane1.setEnabledAt(2,false);     // Hides acquisiton tab: There is not possible to assign an acquisition to a study.
            }else if(nodeLevel == 2){  // Study seleced.
                // Get Patient:
                DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
                this.x = (view.Patient)parentNode.getUserObject();
                Integer patientId = x.getPatientId();
                if(changeData == true){
                    this.controller.changeSelectedPatient(patientId);                   // Selecting by study, everytime must exist an patient.
                    System.out.println("patientsFullName: "+x.toString()+" => patientId: "+patientId);
                }
                // Get Study:
                this.y = (view.Study)selectedNode.getUserObject();
                Integer studyId = y.getStudyId();
                //System.out.println("worklistDate: "+y.toString()+" => studyId: "+studyId);
                //this.StudyNameInput.setText(y.toString());
                
                if(changeData == true){
                    this.jTabbedPane1.setSelectedIndex(1);
                    if(studyId != null){this.controller.changeSelectedStudy(studyId);   // Case of load an existing study.
                    }else{this.controller.changeSelectedStudy(null);}                   // Case of new study.
                }
                this.selectedPatientId = patientId;
                this.selectedStudyId = studyId;
                this.selectedAcquisitionId = null;

            }else if(nodeLevel == 3){  // Acquisition seleced.
                // Get Study:
                DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
                this.y = (view.Study)parentNode.getUserObject();
                Integer studyId = y.getStudyId();
                if(changeData == true){
                    this.controller.changeSelectedStudy(studyId);
                }
                // Get Patient:
                DefaultMutableTreeNode grandfatherNode = (DefaultMutableTreeNode) parentNode.getParent();
                this.x = (view.Patient)grandfatherNode.getUserObject();
                Integer patientId = x.getPatientId();
                if(changeData == true){
                    this.controller.changeSelectedPatient(patientId);                   // Selecting by study, everytime must exist an patient.
                    //System.out.println("patientsFullName: "+x.toString()+" => patientId: "+patientId+" studyDate: "+y.toString()+" => studyId: "+studyId);
                }
                // Get Acquisition:
                this.z = (view.Acquisition)selectedNode.getUserObject();
                Integer acquisitionId = z.getAcquisitionId();
                System.out.println("AcquisitionTime: "+z.toString()+" => acquisitionId: "+acquisitionId);
                if(changeData == true){
                    this.jTabbedPane1.setSelectedIndex(2);
                    if(studyId != null){this.controller.changeSelectedAcquisition(acquisitionId);   // Case of load an existing study.
                    }else{this.controller.changeSelectedAcquisition(null);}                   // Case of new study.
                }
                this.selectedPatientId = patientId;
                this.selectedStudyId = studyId;
                this.selectedAcquisitionId = acquisitionId;

            }else{
                jTabbedPane1.setEnabledAt(1,false); // Hides the second tab.
                jTabbedPane1.setEnabledAt(2,false); // Hides the third tab.
                System.out.println("Patient nor study not selected");
            }

            // Avoids add a new study to 'New Patient' node or a new acquisition to 'New Study' node.
            if(x.toString().equals(newPatient) ){
                jTabbedPane1.setEnabledAt(1,false);     // Hides study tab.
                jTabbedPane1.setEnabledAt(2,false);     // Hides acquisiton tab.
            }else if(y != null && y.toString().equals(newStudy)){
                jTabbedPane1.setEnabledAt(2,false);     // Hides acquisiton tab.
            }

        }catch(SQLException ex){//JOptionPane.ERROR_MESSAGE
            String error_txt = Application.splitError(ex.toString());
            JOptionPane.showMessageDialog(this.DemographicPanel, error_txt, this.MYSQL_EXCEPTION, 2, null);
        }catch(Exception ex){
            String error_txt = Application.splitError(ex.toString());
            JOptionPane.showMessageDialog(this.DemographicPanel, error_txt, this.EXCEPTION, 2, null);
        }
    }
    public TreePath getTreePath(){  // NOT USED
        int selectedTree = jTabbedPane2.getSelectedIndex();
        TreePath path = null;
        if(selectedTree == 0 && PatientTree.getAnchorSelectionPath() != null){   // PatientTree tab is selected and there is a node selected in it.
            path = WorklistTree.getLeadSelectionPath();
        }else if(selectedTree == 1 && PatientTree.getAnchorSelectionPath() != null){
            path = PatientTree.getLeadSelectionPath();
        }else{
            System.out.println("Jtree not selected");
        }
        return path;
    }
    public String parseDate(String dateValue){
        //System.out.println("Date value at start: "+dateValue+" length: "+dateValue.length());
        if(dateValue == null){
            dateValue = Application.now();  // If date is unknown, assigns actual date to the study.
        }
        if(dateValue.length() > 10){
            dateValue = dateValue.substring(0, 10);
        }
        dateValue = dateValue.replaceAll("-", "");
        dateValue = dateValue.replaceAll("/", "");
        dateValue = dateValue.substring(0, 4)+"/"+dateValue.substring(4, 6)+"/"+dateValue.substring(6, 8);
        //System.out.println("Parsed date value: "+dateValue);
        return dateValue;
    }
    public String parseTime(String timeValue){
        //System.out.println("Date value at start: "+dateValue+" length: "+dateValue.length());
        if(timeValue == null){
            timeValue = Application.now();  // If date is unknown, assigns actual date to the study.
        }
        if(timeValue.length() > 10){
            timeValue = timeValue.substring(11, timeValue.length());
        }
        return timeValue;
    }
    public String parseTime2(String timeString) throws ParseException{
        String time = timeString.substring(0, 2)+":"+timeString.substring(2, 4)+":"+timeString.substring(4, 6);
        //System.out.println("Formatted time: "+timeString);
        return time;
    }
    public void setApplication(Application application) {
        this.application = application;
    }
    public void setController(Controller controller) {
        this.controller = controller;
    }

    public void setConsultation(Consultation consultation) {
        this.consultation = consultation;
    }

    public void setPatientTreeView(PatientTreeView patientTreeView) {
        this.patientTreeView = patientTreeView;
    }

    public void setWorklistTreeView(WorklistTreeView worklistTreeView) {
        this.worklistTreeView = worklistTreeView;
    }

    public void run_initComponents(){
        initComponents();
    }

    public void loadImage(File file) {
        ImageIcon iconoCargado = new ImageIcon(file.getPath()); // Creates an ImageIcon from URL path.

            // Resize Icon:
            Image img = iconoCargado.getImage();    // Transform Icon in Image.

            int imgWidth = img.getWidth(UserLabel);
            int imgHeight = img.getHeight(UserLabel);
            int labelWidth = ImagePreviewLabel.getWidth();
            int labelHeight = ImagePreviewLabel.getHeight();

            double scaleFactor = scaleImage(imgWidth,imgHeight,labelWidth,labelHeight);

            // Multiplies original image by scale factor:
            int width = (int) (imgWidth * scaleFactor);
            int height = (int) (imgHeight * scaleFactor);
            //System.out.println(width+" resta "+height);

            Image newimg = img.getScaledInstance(width, height,  java.awt.Image.SCALE_AREA_AVERAGING);   // Resize image.
            iconoCargado = new ImageIcon(newimg);   // Rewrite Icon.

            //System.out.println(img.getWidth(UserLabel)+" Inicial "+img.getHeight(UserLabel));
            //System.out.println(newimg.getWidth(UserLabel)+" Inicial "+newimg.getHeight(UserLabel));

            ImagePreviewLabel.setIcon(iconoCargado);                  // Paints the ImageIcon on a Label.
            ImagePathInput.setText(file.getPath());             // Updates the path value on a text input.
            ImageFileChooser.setSelectedFile(null);             // Reset the ImageFileChooser value for the next use.
    }

    public void updateViewDeleteServerList() {
        if(selectedServerComboBox.getComponentCount() != 0){
            selectedServerComboBox.removeAllItems();
            selectedServerComboBox1.removeAllItems();
        }
    }    
    public void updateViewAddServer(DB2Hash s) {
        Server server = new Server(s);                     // Creates a Server type object to manage the combobox.
        /*if(selectedServerComboBox.getItemCount() == 0){
            selectedServerComboBox.addItem(null);
        }*/
        selectedServerComboBox.addItem(server);
        selectedServerComboBox1.addItem(server);
    }    
}

